diff options
author | 2018-12-20 11:21:36 +0100 | |
---|---|---|
committer | 2018-12-20 12:11:18 +0100 | |
commit | cdce33f987c01a406e86f6aceff9d5ddea6d646a (patch) | |
tree | 0d037652ae89dadbc5ac3d5d97fa551b0adf7676 | |
parent | fileio: fix read_one_line() when reading bytes > 0x7F (diff) | |
download | systemd-cdce33f987c01a406e86f6aceff9d5ddea6d646a.tar.gz systemd-cdce33f987c01a406e86f6aceff9d5ddea6d646a.tar.bz2 systemd-cdce33f987c01a406e86f6aceff9d5ddea6d646a.zip |
test-fileio: add explicit check for safe_fgetc() with 0xFF
-rw-r--r-- | src/test/test-fileio.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 08ed66d4b..bf918c1d1 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -611,7 +611,7 @@ static void test_tempfn(void) { } static const char chars[] = - "Aąę„”\n루"; + "Aąę„”\n루\377"; static void test_fgetc(void) { _cleanup_fclose_ FILE *f = NULL; @@ -624,11 +624,12 @@ static void test_fgetc(void) { assert_se(safe_fgetc(f, &c) == 1); assert_se(c == chars[i]); - assert_se(ungetc(c, f) != EOF); - assert_se(safe_fgetc(f, &c) == 1); + /* EOF is -1, and hence we can't push value 255 in this way */ + assert_se(ungetc(c, f) != EOF || c == EOF); + assert_se(c == EOF || safe_fgetc(f, &c) == 1); assert_se(c == chars[i]); - /* Check that ungetc doesn't care about unsigned char vs signed char */ + /* But it works when we push it properly cast */ assert_se(ungetc((unsigned char) c, f) != EOF); assert_se(safe_fgetc(f, &c) == 1); assert_se(c == chars[i]); |