[LLVMbugs] [Bug 17200] New: bad fixit for Wstrncat-size in macro
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Sep 11 21:45:54 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=17200
Bug ID: 17200
Summary: bad fixit for Wstrncat-size in macro
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: nlewycky at google.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Example:
nlewycky at ducttape:~$ llvm/Debug+Asserts/bin/clang -fsyntax-only strncat-macro.c
In file included from strncat-macro.c:1:
./strncat-hdr.h:6:24: warning: the value of the size argument in 'strncat' is
too large, might lead to a buffer overflow [-Wstrncat-size]
(strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
^~~~~~~~~~~~~~~~~~~
./strncat-hdr.h:5:24: note: change the argument to be the free space in the
destination buffer minus the terminating null byte
(strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
^~~~~~~~~~~~~~~~~~~
sizeof(dtString) - strlen(dtString) - 1
1 warning generated.
Of course writing in "dtString" for macro argument "A" isn't right. Here's the
two-file testcase:
nlewycky at ducttape:~$ cat strncat-macro.c
#include "strncat-hdr.h"
void test() {
char dtString[64];
char usecString[64];
STRSCAT(dtString, usecString);
}
nlewycky at ducttape:~$ cat strncat-hdr.h
#define strncat(dest, src, n) __builtin_strncat (dest, src, n)
unsigned long strlen(const char *s);
#define STRSCAT(A,B) \
(strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130912/37261c80/attachment.html>
More information about the llvm-bugs
mailing list