Thread (4 messages) flat view 4 messages, 3 authors, 2016-08-05

Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning

From: Johannes Sixt <hidden>
Date: 2016-08-05 05:40:55

Possibly related (same subject, not in this thread)

Am 05.08.2016 um 07:36 schrieb Johannes Sixt:
Am 05.08.2016 um 00:39 schrieb Junio C Hamano:
quoted
@@ -955,12 +955,10 @@ void **nedpindependent_comalloc(nedpool *p,
size_t elems, size_t *sizes, void **
  */
 char *strdup(const char *s1)
 {
-    char *s2 = 0;
-    if (s1) {
-        size_t len = strlen(s1) + 1;
-        s2 = malloc(len);
+    size_t len = strlen(s1) + 1;
+    s2 = malloc(len);
+    if (s1)
It does not make sense to check s1 for NULL when it was passed to
strlen() earlier; strlen() does not accept NULL, either...
Oh! This is a typo. You meant to check s2 for NULL.

And the declaration for s2 should remain, of course.
quoted
         memcpy(s2, s1, len);
-    }
     return s2;
 }
 #endif
-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help