diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 13:16:53 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 13:16:53 -0300 |
| commit | cf71a5ddc742692fad813f89f1c9ef53e1ffde0f (patch) | |
| tree | df02305ff3cf05908f21829384e3a7f8699d2331 /lstrlib.c | |
| parent | 2c32bff60987d38a60a58d4f0123f3783da60a63 (diff) | |
| download | lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.tar.gz lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.tar.bz2 lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.zip | |
Details
Several small improvements (code style, warnings, comments, more tests),
in particular:
- 'lua_topointer' extended to handle strings
- raises an error in 'string.format("%10q")' ('%q' with modifiers)
- in the manual for 'string.format', the term "option" replaced by
"conversion specifier" (the term used by the C standard)
Diffstat (limited to 'lstrlib.c')
| -rw-r--r-- | lstrlib.c | 6 |
1 files changed, 4 insertions, 2 deletions
| @@ -181,7 +181,7 @@ static int str_byte (lua_State *L) { | |||
| 181 | size_t pose = getendpos(L, 3, pi, l); | 181 | size_t pose = getendpos(L, 3, pi, l); |
| 182 | int n, i; | 182 | int n, i; |
| 183 | if (posi > pose) return 0; /* empty interval; return no values */ | 183 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 184 | if (pose - posi >= INT_MAX) /* arithmetic overflow? */ | 184 | if (pose - posi >= (size_t)INT_MAX) /* arithmetic overflow? */ |
| 185 | return luaL_error(L, "string slice too long"); | 185 | return luaL_error(L, "string slice too long"); |
| 186 | n = (int)(pose - posi) + 1; | 186 | n = (int)(pose - posi) + 1; |
| 187 | luaL_checkstack(L, n, "string slice too long"); | 187 | luaL_checkstack(L, n, "string slice too long"); |
| @@ -1159,7 +1159,7 @@ static int str_format (lua_State *L) { | |||
| 1159 | char *buff = luaL_prepbuffsize(&b, MAX_ITEM); /* to put formatted item */ | 1159 | char *buff = luaL_prepbuffsize(&b, MAX_ITEM); /* to put formatted item */ |
| 1160 | int nb = 0; /* number of bytes in added item */ | 1160 | int nb = 0; /* number of bytes in added item */ |
| 1161 | if (++arg > top) | 1161 | if (++arg > top) |
| 1162 | luaL_argerror(L, arg, "no value"); | 1162 | return luaL_argerror(L, arg, "no value"); |
| 1163 | strfrmt = scanformat(L, strfrmt, form); | 1163 | strfrmt = scanformat(L, strfrmt, form); |
| 1164 | switch (*strfrmt++) { | 1164 | switch (*strfrmt++) { |
| 1165 | case 'c': { | 1165 | case 'c': { |
| @@ -1186,6 +1186,8 @@ static int str_format (lua_State *L) { | |||
| 1186 | break; | 1186 | break; |
| 1187 | } | 1187 | } |
| 1188 | case 'q': { | 1188 | case 'q': { |
| 1189 | if (form[2] != '\0') /* modifiers? */ | ||
| 1190 | return luaL_error(L, "specifier '%%q' cannot have modifiers"); | ||
| 1189 | addliteral(L, &b, arg); | 1191 | addliteral(L, &b, arg); |
| 1190 | break; | 1192 | break; |
| 1191 | } | 1193 | } |
