diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-20 14:36:32 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-20 14:36:32 -0200 |
commit | 8b88ab07f7cfc216407a88d75ad8f0546224c8d7 (patch) | |
tree | 71acdcf4416d114087419863f45186270d5c8d15 | |
parent | 2779ceeb125e603ea667171d9362e0b766b7abae (diff) | |
download | lua-8b88ab07f7cfc216407a88d75ad8f0546224c8d7.tar.gz lua-8b88ab07f7cfc216407a88d75ad8f0546224c8d7.tar.bz2 lua-8b88ab07f7cfc216407a88d75ad8f0546224c8d7.zip |
more controled use of `sprintf'
-rw-r--r-- | lobject.c | 27 | ||||
-rw-r--r-- | lua.c | 8 | ||||
-rw-r--r-- | lzio.h | 5 |
3 files changed, 26 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.53 2000/10/09 13:47:32 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.54 2000/10/10 19:53:20 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -76,10 +76,13 @@ int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */ | |||
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | /* maximum length of a string format for `luaO_verror' */ | ||
80 | #define MAX_VERROR 280 | ||
81 | |||
79 | /* this function needs to handle only '%d' and '%.XXs' formats */ | 82 | /* this function needs to handle only '%d' and '%.XXs' formats */ |
80 | void luaO_verror (lua_State *L, const char *fmt, ...) { | 83 | void luaO_verror (lua_State *L, const char *fmt, ...) { |
81 | va_list argp; | 84 | va_list argp; |
82 | char buff[600]; /* to hold formatted message */ | 85 | char buff[MAX_VERROR]; /* to hold formatted message */ |
83 | va_start(argp, fmt); | 86 | va_start(argp, fmt); |
84 | vsprintf(buff, fmt, argp); | 87 | vsprintf(buff, fmt, argp); |
85 | va_end(argp); | 88 | va_end(argp); |
@@ -88,8 +91,10 @@ void luaO_verror (lua_State *L, const char *fmt, ...) { | |||
88 | 91 | ||
89 | 92 | ||
90 | void luaO_chunkid (char *out, const char *source, int bufflen) { | 93 | void luaO_chunkid (char *out, const char *source, int bufflen) { |
91 | if (*source == '=') | 94 | if (*source == '=') { |
92 | sprintf(out, "%.*s", bufflen-1, source+1); /* remove first char */ | 95 | strncpy(out, source+1, bufflen); /* remove first char */ |
96 | out[bufflen-1] = '\0'; /* ensures null termination */ | ||
97 | } | ||
93 | else { | 98 | else { |
94 | if (*source == '@') { | 99 | if (*source == '@') { |
95 | int l; | 100 | int l; |
@@ -98,19 +103,23 @@ void luaO_chunkid (char *out, const char *source, int bufflen) { | |||
98 | l = strlen(source); | 103 | l = strlen(source); |
99 | if (l>bufflen) { | 104 | if (l>bufflen) { |
100 | source += (l-bufflen); /* get last part of file name */ | 105 | source += (l-bufflen); /* get last part of file name */ |
101 | sprintf(out, "file `...%s'", source); | 106 | sprintf(out, "file `...%.99s'", source); |
102 | } | 107 | } |
103 | else | 108 | else |
104 | sprintf(out, "file `%s'", source); | 109 | sprintf(out, "file `%.99s'", source); |
105 | } | 110 | } |
106 | else { | 111 | else { |
107 | int len = strcspn(source, "\n"); /* stop at first newline */ | 112 | int len = strcspn(source, "\n"); /* stop at first newline */ |
108 | bufflen -= sizeof("string \"%.*s...\""); | 113 | bufflen -= sizeof("string \"%.*s...\""); |
109 | if (len > bufflen) len = bufflen; | 114 | if (len > bufflen) len = bufflen; |
110 | if (source[len] != '\0') /* must truncate? */ | 115 | if (source[len] != '\0') { /* must truncate? */ |
111 | sprintf(out, "string \"%.*s...\"", len, source); | 116 | strcpy(out, "string \""); |
117 | out += strlen(out); | ||
118 | strncpy(out, source, len); | ||
119 | strcpy(out+len, "...\""); | ||
120 | } | ||
112 | else | 121 | else |
113 | sprintf(out, "string \"%s\"", source); | 122 | sprintf(out, "string \"%.99s\"", source); |
114 | } | 123 | } |
115 | } | 124 | } |
116 | } | 125 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.53 2000/10/09 15:46:43 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.54 2000/10/17 13:36:24 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -115,7 +115,7 @@ static void print_message (void) { | |||
115 | 115 | ||
116 | 116 | ||
117 | static void print_version (void) { | 117 | static void print_version (void) { |
118 | printf("%s %s\n", LUA_VERSION, LUA_COPYRIGHT); | 118 | printf("%.80s %.80s\n", LUA_VERSION, LUA_COPYRIGHT); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
@@ -255,7 +255,7 @@ static int handle_argv (char *argv[], struct Options *opt) { | |||
255 | return EXIT_FAILURE; | 255 | return EXIT_FAILURE; |
256 | } | 256 | } |
257 | if (ldo(lua_dostring, argv[i]) != 0) { | 257 | if (ldo(lua_dostring, argv[i]) != 0) { |
258 | fprintf(stderr, "lua: error running argument `%s'\n", argv[i]); | 258 | fprintf(stderr, "lua: error running argument `%.99s'\n", argv[i]); |
259 | return EXIT_FAILURE; | 259 | return EXIT_FAILURE; |
260 | } | 260 | } |
261 | break; | 261 | break; |
@@ -289,7 +289,7 @@ static void getstacksize (int argc, char *argv[], struct Options *opt) { | |||
289 | if (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 's') { | 289 | if (argc >= 2 && argv[1][0] == '-' && argv[1][1] == 's') { |
290 | int stacksize = atoi(&argv[1][2]); | 290 | int stacksize = atoi(&argv[1][2]); |
291 | if (stacksize <= 0) { | 291 | if (stacksize <= 0) { |
292 | fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]); | 292 | fprintf(stderr, "lua: invalid stack size ('%.20s')\n", &argv[1][2]); |
293 | exit(EXIT_FAILURE); | 293 | exit(EXIT_FAILURE); |
294 | } | 294 | } |
295 | opt->stacksize = stacksize; | 295 | opt->stacksize = stacksize; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lzio.h,v 1.5 1999/08/16 20:52:00 roberto Exp roberto $ | 2 | ** $Id: lzio.h,v 1.6 2000/05/24 13:54:49 roberto Exp roberto $ |
3 | ** Buffered streams | 3 | ** Buffered streams |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -33,9 +33,12 @@ size_t zread (ZIO* z, void* b, size_t n); /* read next n bytes */ | |||
33 | #define zname(z) ((z)->name) | 33 | #define zname(z) ((z)->name) |
34 | 34 | ||
35 | 35 | ||
36 | |||
36 | /* --------- Private Part ------------------ */ | 37 | /* --------- Private Part ------------------ */ |
37 | 38 | ||
39 | #ifndef ZBSIZE | ||
38 | #define ZBSIZE 256 /* buffer size */ | 40 | #define ZBSIZE 256 /* buffer size */ |
41 | #endif | ||
39 | 42 | ||
40 | struct zio { | 43 | struct zio { |
41 | size_t n; /* bytes still unread */ | 44 | size_t n; /* bytes still unread */ |