aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/parse_config.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index c511d97fb..b7c3a00e0 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -128,8 +128,8 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
128 int ntokens, mintokens; 128 int ntokens, mintokens;
129 int t, len; 129 int t, len;
130 130
131 ntokens = flags & 0xFF; 131 ntokens = (uint8_t)flags;
132 mintokens = (flags & 0xFF00) >> 8; 132 mintokens = (uint8_t)(flags >> 8);
133 133
134 if (parser == NULL) 134 if (parser == NULL)
135 return 0; 135 return 0;
@@ -159,7 +159,8 @@ again:
159 parser->data = xstrdup(line); 159 parser->data = xstrdup(line);
160 160
161 /* Tokenize the line */ 161 /* Tokenize the line */
162 for (t = 0; *line && *line != delims[0] && t < ntokens; t++) { 162 t = 0;
163 do {
163 /* Pin token */ 164 /* Pin token */
164 tokens[t] = line; 165 tokens[t] = line;
165 166
@@ -179,10 +180,10 @@ again:
179 } 180 }
180 181
181 /* Token not terminated? */ 182 /* Token not terminated? */
182 if (line[0] == delims[0]) 183 if (*line == delims[0])
183 *line = '\0'; 184 *line = '\0';
184 else if (line[0] != '\0') 185 else if (*line != '\0')
185 *(line++) = '\0'; 186 *line++ = '\0';
186 187
187#if 0 /* unused so far */ 188#if 0 /* unused so far */
188 if (flags & PARSE_ESCAPE) { 189 if (flags & PARSE_ESCAPE) {
@@ -201,17 +202,20 @@ again:
201 *to = '\0'; 202 *to = '\0';
202 } 203 }
203#endif 204#endif
204
205 /* Skip possible delimiters */ 205 /* Skip possible delimiters */
206 if (flags & PARSE_COLLAPSE) 206 if (flags & PARSE_COLLAPSE)
207 line += strspn(line, delims + 1); 207 line += strspn(line, delims + 1);
208 } 208
209 t++;
210 } while (*line && *line != delims[0] && t < ntokens);
209 211
210 if (t < mintokens) { 212 if (t < mintokens) {
211 bb_error_msg("bad line %u: %d tokens found, %d needed", 213 bb_error_msg("bad line %u: %d tokens found, %d needed",
212 parser->lineno, t, mintokens); 214 parser->lineno, t, mintokens);
213 if (flags & PARSE_MIN_DIE) 215 if (flags & PARSE_MIN_DIE)
214 xfunc_die(); 216 xfunc_die();
217 if (flags & PARSE_KEEP_COPY)
218 free(parser->data);
215 goto again; 219 goto again;
216 } 220 }
217 221