Skip to content

Commit c6c9e18

Browse files
rscharfegitster
authored andcommitted
nedmalloc: work around overzealous GCC 6 warning
With GCC 6, the strdup() function is declared with the "nonnull" attribute, stating that it is not allowed to pass a NULL value as parameter. In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded and NULL parameters are handled gracefully. GCC 6 complains about that now because it thinks that NULL cannot be passed to strdup() anyway. Because the callers in this project of strdup() must be prepared to call any implementation of strdup() supplied by the platform, so it is pointless to pretend that it is OK to call it with NULL. Remove the conditional based on NULL-ness of the input; this squelches the warning. Check the return value of malloc() instead to make sure we actually got the memory to write to. See https://gcc.gnu.org/gcc-6/porting_to.html for details. Diagnosed-by: Johannes Schindelin <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e70105 commit c6c9e18

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compat/nedmalloc/nedmalloc.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,11 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **
955955
*/
956956
char *strdup(const char *s1)
957957
{
958-
char *s2 = 0;
959-
if (s1) {
960-
size_t len = strlen(s1) + 1;
961-
s2 = malloc(len);
958+
size_t len = strlen(s1) + 1;
959+
char *s2 = malloc(len);
960+
961+
if (s2)
962962
memcpy(s2, s1, len);
963-
}
964963
return s2;
965964
}
966965
#endif

0 commit comments

Comments
 (0)