diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2006-08-24 14:25:39 +0000 |
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2006-08-24 14:25:39 +0000 |
| commit | 8e8ffce4115d3520649d75b0037cca5756ceaba2 (patch) | |
| tree | b8997cc9eb2ef6603fdac558a7bb99946f0ae16d /llvm | |
| parent | e08b9853cc1baf266fe472ffcc00f4713aab58da (diff) | |
| download | bcm5719-llvm-8e8ffce4115d3520649d75b0037cca5756ceaba2.tar.gz bcm5719-llvm-8e8ffce4115d3520649d75b0037cca5756ceaba2.zip | |
Remove a FIXME. Don't use strlcpy that isn't available on non-BSD platforms
and ensure that a memory overrun won't occur while still writing Length
bytes in the outstring function.
llvm-svn: 29855
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/CodeGen/MachOWriter.h | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/llvm/include/llvm/CodeGen/MachOWriter.h b/llvm/include/llvm/CodeGen/MachOWriter.h index 61ca8d736ab..36fc6169e78 100644 --- a/llvm/include/llvm/CodeGen/MachOWriter.h +++ b/llvm/include/llvm/CodeGen/MachOWriter.h @@ -575,17 +575,15 @@ namespace llvm { outxword(Output, X); } void outstring(DataBuffer &Output, std::string &S, unsigned Length) { - char *buffer = (char *)calloc(1, Length); - unsigned i; - // FIXME: it is unclear if mach-o requires null terminated strings, or - // if a string of 16 bytes with no null terminator is ok. If so, - // we should switch to strncpy. - strlcpy(buffer, S.c_str(), Length); + unsigned len_to_copy = S.length() < Length ? S.length() : Length; + unsigned len_to_fill = S.length() < Length ? Length-S.length() : 0; - for (i = 0; i < Length; ++i) - outbyte(Output, buffer[i]); + for (unsigned i = 0; i < len_to_copy; ++i) + outbyte(Output, S[i]); + + for (unsigned i = 0; i < len_to_fill; ++i) + outbyte(Output, 0); - free(buffer); } private: void EmitGlobal(GlobalVariable *GV); |

