5da46537f3
safe counterparts, okay jolan@
57 lines
1.9 KiB
Plaintext
57 lines
1.9 KiB
Plaintext
$OpenBSD: patch-src_lobject_c,v 1.1 2006/01/18 11:17:03 pedro Exp $
|
|
--- src/lobject.c.orig Thu Apr 3 10:35:34 2003
|
|
+++ src/lobject.c Tue Jan 17 14:06:46 2006
|
|
@@ -161,35 +161,33 @@ const char *luaO_pushfstring (lua_State
|
|
|
|
|
|
void luaO_chunkid (char *out, const char *source, int bufflen) {
|
|
- if (*source == '=') {
|
|
- strncpy(out, source+1, bufflen); /* remove first char */
|
|
- out[bufflen-1] = '\0'; /* ensures null termination */
|
|
- }
|
|
+ if (*source == '=')
|
|
+ strlcpy(out, source+1, bufflen); /* remove first char */
|
|
else { /* out = "source", or "...source" */
|
|
if (*source == '@') {
|
|
- int l;
|
|
+ int l, m;
|
|
source++; /* skip the `@' */
|
|
- bufflen -= sizeof(" `...' ");
|
|
l = strlen(source);
|
|
- strcpy(out, "");
|
|
- if (l>bufflen) {
|
|
- source += (l-bufflen); /* get last part of file name */
|
|
- strcat(out, "...");
|
|
+ m = bufflen - sizeof(" '...' ");
|
|
+ strlcpy(out, "", bufflen);
|
|
+ if (l > m) {
|
|
+ source += (l-m); /* get last part of file name */
|
|
+ strlcat(out, "...", bufflen);
|
|
}
|
|
- strcat(out, source);
|
|
+ strlcat(out, source, bufflen);
|
|
}
|
|
else { /* out = [string "string"] */
|
|
- int len = strcspn(source, "\n"); /* stop at first newline */
|
|
- bufflen -= sizeof(" [string \"...\"] ");
|
|
- if (len > bufflen) len = bufflen;
|
|
- strcpy(out, "[string \"");
|
|
+ int pos = strcspn(source, "\n\r"); /* stop at first newline */
|
|
+ int len = bufflen - sizeof(" [string \"...\"] ");
|
|
+ if (pos > len) pos = len;
|
|
+ strlcpy(out, "[string \"", bufflen);
|
|
if (source[len] != '\0') { /* must truncate? */
|
|
- strncat(out, source, len);
|
|
- strcat(out, "...");
|
|
+ strlcat(out, source, len);
|
|
+ strlcat(out, "...", bufflen);
|
|
}
|
|
else
|
|
- strcat(out, source);
|
|
- strcat(out, "\"]");
|
|
+ strlcat(out, source, bufflen);
|
|
+ strlcat(out, "\"]", bufflen);
|
|
}
|
|
}
|
|
}
|