mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29855 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
687bc49d1a
commit
0569eee66b
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user