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

Fix a few issues with the C generator (part 7) #20366

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eafer
Copy link
Contributor

@eafer eafer commented Dec 21, 2024

Another new warning I've noticed when building our api with the latest version:

/root/avh-api/c/api/api/ArmAPI.c: In function ‘ArmAPI_v1CreateImage’:
/root/avh-api/c/api/api/ArmAPI.c:1346:32: error: assignment to ‘int’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
 1346 |         valueForm_encapsulated = calloc(1,MAX_NUMBER_LENGTH);
      |                                ^
/root/avh-api/c/api/api/ArmAPI.c:1347:18: error: passing argument 1 of ‘snprintf’ makes pointer from integer without a cast [-Werror=int-conversion]
 1347 |         snprintf(valueForm_encapsulated, MAX_NUMBER_LENGTH, "%d", *encapsulated);
      |                  ^~~~~~~~~~~~~~~~~~~~~~
      |                  |
      |                  int
In file included from /root/avh-api/c/api/api/ArmAPI.c:2:
/usr/include/stdio.h:378:39: note: expected ‘char * restrict’ but argument is of type ‘int’
  378 | extern int snprintf (char *__restrict __s, size_t __maxlen,
      |                      ~~~~~~~~~~~~~~~~~^~~

This is not actually a regression, the code was always broken but recent changes made the warning show up. This pull request does the following:

  1. Update the test schema to cover this broken case.
  2. Change the compiler flags to ban implicit int to pointer conversions, so that automated testing will not miss these warnings.
  3. Fix the actual bug, changing the type of valueForm to char *.

There are other issues with formData input. I think valueForm should become char * for all types, not just bool. But this involves bigger changes, so I might look into it at some later time.

@eafer
Copy link
Contributor Author

eafer commented Dec 21, 2024

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

Successfully merging this pull request may close these issues.

2 participants