Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf_len declaration is incompatible with definition #11

Closed
michaelforney opened this issue Jun 17, 2019 · 0 comments · Fixed by #14
Closed

utf_len declaration is incompatible with definition #11

michaelforney opened this issue Jun 17, 2019 · 0 comments · Fixed by #14

Comments

@michaelforney
Copy link
Contributor

With HAVE_ANSI_PROTOS, utf_len is declared in funcs.h as

int utf_len(unsigned char ch);

and defined in charset.c as

int utf_len(ch)
	unsigned char ch;
{ ... }

However, according to the C standard (C89 3.5.4.3, C99 6.7.5.3p15),

If one type has a parameter type list and the other type is specified by a function definition that contains a (possibly empty) identifier list, both shall agree in the number of parameters, and the type of each prototype parameter shall be compatible with the type that results from the application of the default argument promotions to the type of the corresponding identifier.

Since int can represent all the values of unsigned char, ch gets promoted to int by default argument promotions. unsigned char is not compatible with int, making the two function types incompatible.

To fix this, the prototype declaration in funcs.h needs to be updated to int utf_len(int ch). However, since these declarations are autogenerated from the definitions, it is probably easier to resolve by just changing the type in the definition from unsigned char to int.

This same issue also affects pappend and set_status_col in line.c.

michaelforney added a commit to michaelforney/less that referenced this issue Jul 6, 2019
…otion

In order for a prototype declaration and non-prototype function
definition to be compatible, the promoted type of the non-prototype
function parameters must be compatible with the type of the corresponding
prototype parameter.

Since funcs.h is autogenerated by mkfuncs.pl which copies the parameter
types as-is, use the promoted type in the definitions so that the types
are unaffected by default argument promotion.

Fixes gwsw#11
@gwsw gwsw closed this as completed in #14 Jul 6, 2019
gwsw pushed a commit that referenced this issue Jul 6, 2019
…otion (#14)

In order for a prototype declaration and non-prototype function
definition to be compatible, the promoted type of the non-prototype
function parameters must be compatible with the type of the corresponding
prototype parameter.

Since funcs.h is autogenerated by mkfuncs.pl which copies the parameter
types as-is, use the promoted type in the definitions so that the types
are unaffected by default argument promotion.

Fixes #11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant