Skip to content

Commit 6ea33d7

Browse files
committed
Modify lib/ff_ini_parser.c to run unit test.
1 parent bef9174 commit 6ea33d7

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

lib/ff_ini_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
177177
/* See documentation in header file. */
178178
int ini_parse_file(FILE* file, ini_handler handler, void* user)
179179
{
180+
if (file == NULL)
181+
return -1;
180182
return ini_parse_stream((ini_reader)fgets, file, handler, user);
181183
}
182184

tests/unit/test_ff_ini_parser.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,22 @@ test_ini_parse_file_normal(void **state)
304304
}
305305

306306
/* ------------------------------------------------------------------------ */
307-
/* TC-U-P0-INI-12: ini_parse_file with NULL FILE* — SKIP */
307+
/* TC-U-P0-INI-12: ini_parse_file(NULL, ...) -> -1 (defensive NULL guard) */
308308
/* */
309-
/* Empirically verified during Stage-2 implementation that calling */
310-
/* ini_parse_file(NULL, ...) */
311-
/* on glibc 2.x triggers SIGSEGV inside fgets(_, _, NULL). This is a real */
312-
/* robustness gap in lib/ff_ini_parser.c — fixing it requires guarding the */
313-
/* file pointer or wrapping fgets, which is out-of-scope for the unit-test */
314-
/* phase (DP-U-11 forbids editing lib source). */
315-
/* */
316-
/* Filed as FU-S2-NULLFILE for follow-up; this TC is preserved as `skip()` */
317-
/* so that future commits adding the NULL-guard automatically re-enable it. */
309+
/* lib/ff_ini_parser.c gained an explicit NULL FILE* check at the entry of */
310+
/* ini_parse_file (commit FU-S2-NULLFILE), aligning the failure semantics */
311+
/* with ini_parse(filename) returning -1 on fopen failure. The TC verifies */
312+
/* the function: */
313+
/* (a) returns -1 (never crashes / SIGSEGVs) */
314+
/* (b) does not invoke the handler (zero records captured) */
318315
/* ------------------------------------------------------------------------ */
319316
static void
320317
test_ini_parse_file_null(void **state)
321318
{
322-
(void)state;
323-
skip(); /* FU-S2-NULLFILE: lib/ff_ini_parser.c lacks NULL FILE* guard */
319+
capture_ctx_t *ctx = *state;
320+
int rv = ini_parse_file(NULL, capture_handler, ctx);
321+
assert_int_equal(rv, -1);
322+
assert_int_equal(ctx->count, 0);
324323
}
325324

326325
/* ------------------------------------------------------------------------ */

0 commit comments

Comments
 (0)