mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Nitpicks to the previous commit.
We enforce by assertion that the target buffer size is nonzero before subtracting 1 from it; the call to fatal() is replaced by another assert so that it will give clearer diagnostic information if it fails; the variable holding the return value of strlen should be size_t and its declaration should be in a C90-compatible location. Finally, the reason why the function needs to be exist is clarified.
This commit is contained in:
11
misc.c
11
misc.c
@ -361,15 +361,14 @@ void draw_text_outline(drawing *dr, int x, int y, int fonttype,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* kludge for non-compliant sprintf() */
|
/* kludge for sprintf() in Rockbox not supporting "%-8.8s" */
|
||||||
void copy_left_justified(char *buf, size_t sz, const char *str)
|
void copy_left_justified(char *buf, size_t sz, const char *str)
|
||||||
{
|
{
|
||||||
|
size_t len = strlen(str);
|
||||||
|
assert(sz > 0);
|
||||||
memset(buf, ' ', sz - 1);
|
memset(buf, ' ', sz - 1);
|
||||||
int len = strlen(str);
|
assert(len <= sz - 1);
|
||||||
if(len <= sz - 1)
|
memcpy(buf, str, len);
|
||||||
memcpy(buf, str, len);
|
|
||||||
else
|
|
||||||
fatal("overrun");
|
|
||||||
buf[sz - 1] = 0;
|
buf[sz - 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user