Skip to content

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

@wing328 wing328 added this to the 7.11.0 milestone Dec 22, 2024
@wing328 wing328 merged commit 812d89c into OpenAPITools:master Dec 26, 2024
19 checks passed
@eafer
Copy link
Contributor Author

eafer commented Dec 26, 2024

Great! Final pull request here: #20378.

timon-sbr pushed a commit to timon-sbr/openapi-generator that referenced this pull request Mar 13, 2025
* [C] Test nullable booleans in form data

* [C] Ban implicit int to pointer conversions

* [C] Declare valueForm for bool as char *

* Update samples
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