[llvm-commits] CVS: llvm/include/llvm/CodeGen/MachOWriter.h
Reid Spencer
reid at x10sys.com
Thu Aug 24 07:25:53 PDT 2006
Changes in directory llvm/include/llvm/CodeGen:
MachOWriter.h updated: 1.2 -> 1.3
---
Log message:
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.
---
Diffs of the changes: (+7 -9)
MachOWriter.h | 16 +++++++---------
1 files changed, 7 insertions(+), 9 deletions(-)
Index: llvm/include/llvm/CodeGen/MachOWriter.h
diff -u llvm/include/llvm/CodeGen/MachOWriter.h:1.2 llvm/include/llvm/CodeGen/MachOWriter.h:1.3
--- llvm/include/llvm/CodeGen/MachOWriter.h:1.2 Wed Aug 23 16:33:27 2006
+++ llvm/include/llvm/CodeGen/MachOWriter.h Thu Aug 24 09:25:39 2006
@@ -575,17 +575,15 @@
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);
More information about the llvm-commits
mailing list