This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/30426] New: Warning when using strndup


The tiny test program below produces a warning (specifics commented in code
below). From my understanding, no warning should appear on compilation.
Current workaround: Warning disappears once line 2 (right after #include) is
uncommented.

Code:
---------------------------------------------------------------
#include <string.h>
// extern char *strndup (__const char *__string, size_t __n);

int main() {
  char *str="one two three",
       *one=0;

  // command below produces warning
  // "a.c:18: warning: assignment makes pointer from integer without a cast"
  // on openSuSE 10.0 (gcc (GCC) 4.0.2 20050901 (prerelease) (SUSE Linux))

  // command below produces warning
  // "a.c:18: warning: incompatible implicit declaration of built-in function
?strndup?"
  // on openSuSE 10.2 (gcc (GCC) 4.1.2 20061115 (prerelease) (SUSE Linux))

  // warnings disappear when line 3 is uncommented.

  one = strndup(str,3);
}
---------------------------------------------------------------


-- 
           Summary: Warning when using strndup
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: raimund at cs dot auckland dot ac dot nz


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30426


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]