@@ -44,12 +44,12 @@ typedef struct {
44
44
size_t num_left ;
45
45
} ini_parse_string_ctx ;
46
46
47
- /* Strip whitespace chars off end of given string, in place. Return s. */
48
- static char * ini_rstrip (char * s )
47
+ /* Strip whitespace chars off end of given string, in place. end must be a
48
+ pointer to the NUL terminator at the end of the string. Return s. */
49
+ static char * ini_rstrip (char * s , char * end )
49
50
{
50
- char * p = s + strlen (s );
51
- while (p > s && isspace ((unsigned char )(* -- p )))
52
- * p = '\0' ;
51
+ while (end > s && isspace ((unsigned char )(* -- end )))
52
+ * end = '\0' ;
53
53
return s ;
54
54
}
55
55
@@ -178,7 +178,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
178
178
start += 3 ;
179
179
}
180
180
#endif
181
- start = ini_rstrip (ini_lskip (start ));
181
+ start = ini_rstrip (ini_lskip (start ), line + offset );
182
182
183
183
if (strchr (INI_START_COMMENT_PREFIXES , * start )) {
184
184
/* Start-of-line comment */
@@ -187,9 +187,8 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
187
187
else if (* prev_name && * start && start > line ) {
188
188
#if INI_ALLOW_INLINE_COMMENTS
189
189
end = ini_find_chars_or_comment (start , NULL );
190
- if (* end )
191
- * end = '\0' ;
192
- ini_rstrip (start );
190
+ * end = '\0' ;
191
+ ini_rstrip (start , end );
193
192
#endif
194
193
/* Non-blank line with leading whitespace, treat as continuation
195
194
of previous name's value (as per Python configparser). */
@@ -221,15 +220,14 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
221
220
end = ini_find_chars_or_comment (start , "=:" );
222
221
if (* end == '=' || * end == ':' ) {
223
222
* end = '\0' ;
224
- name = ini_rstrip (start );
223
+ name = ini_rstrip (start , end );
225
224
value = end + 1 ;
226
225
#if INI_ALLOW_INLINE_COMMENTS
227
226
end = ini_find_chars_or_comment (value , NULL );
228
- if (* end )
229
- * end = '\0' ;
227
+ * end = '\0' ;
230
228
#endif
231
229
value = ini_lskip (value );
232
- ini_rstrip (value );
230
+ ini_rstrip (value , end );
233
231
234
232
#if INI_ALLOW_MULTILINE
235
233
ini_strncpy0 (prev_name , name , sizeof (prev_name ));
@@ -242,7 +240,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
242
240
/* No '=' or ':' found on name[=:]value line */
243
241
#if INI_ALLOW_NO_VALUE
244
242
* end = '\0' ;
245
- name = ini_rstrip (start );
243
+ name = ini_rstrip (start , end );
246
244
if (!HANDLER (user , section , name , NULL ) && !error )
247
245
error = lineno ;
248
246
#else
0 commit comments