Skip to content

Conversation

@wkliao
Copy link
Member

@wkliao wkliao commented Aug 1, 2025

Check request size against PTRDIFF_MAX before calling malloc, calloc, and realloc. Otherwise, gcc 9 and later complain with thie warning message.

In file included from var_getput.c:17:
var_getput.c: In function 'ncmpi_mput_var':
../../../PnetCDF/src/drivers/include/common.h:83:26: warning: argument 1 range [18446744065119617024, 18446744073709551612] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
   83 | #define NCI_Malloc(a)    malloc(a)
      |                          ^~~~~~~~~
var_getput.c:20555:19: note: in expansion of macro 'NCI_Malloc'
20555 |     reqs = (int*) NCI_Malloc(sizeof(int) * nvars);
      |                   ^~~~~~~~~~
In file included from var_getput.c:12:
/usr/include/stdlib.h:539:14: note: in a call to allocation function
'malloc' declared here
  539 | extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
      |              ^~~~~~

Check request size against PTRDIFF_MAX before calling malloc,
calloc, and realloc. Otherwise, gcc 9 and later complain with
thie warning message.

In file included from var_getput.c:17:
var_getput.c: In function 'ncmpi_mput_var':
../../../PnetCDF/src/drivers/include/common.h:83:26: warning:
argument 1 range [18446744065119617024, 18446744073709551612] exceeds
maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
   83 | #define NCI_Malloc(a)    malloc(a)
      |                          ^~~~~~~~~
var_getput.c:20555:19: note: in expansion of macro 'NCI_Malloc'
20555 |     reqs = (int*) NCI_Malloc(sizeof(int) * nvars);
      |                   ^~~~~~~~~~
In file included from var_getput.c:12:
/usr/include/stdlib.h:539:14: note: in a call to allocation function
'malloc' declared here
  539 | extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
      |              ^~~~~~
@wkliao wkliao merged commit 2f89002 into master Aug 2, 2025
4 checks passed
@wkliao wkliao deleted the malloc_warn branch September 16, 2025 20:51
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 this pull request may close these issues.

2 participants