]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/test/test-fileio.c
codespell: fix spelling errors
[thirdparty/systemd.git] / src / test / test-fileio.c
index 2ddaabe7f896913cf94ebc429640adb91750b65c..211def88ebb587e490c79e11e44788fda0b2ed41 100644 (file)
@@ -629,18 +629,22 @@ static void test_tempfn(void) {
 static const char chars[] =
         "Aąę„”\n루\377";
 
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+
 static void test_fgetc(void) {
         _cleanup_fclose_ FILE *f = NULL;
         char c;
 
-        f = fmemopen((void*) chars, sizeof(chars), "re");
+        f = fmemopen_unlocked((void*) chars, sizeof(chars), "re");
         assert_se(f);
 
         for (unsigned i = 0; i < sizeof(chars); i++) {
                 assert_se(safe_fgetc(f, &c) == 1);
                 assert_se(c == chars[i]);
 
-                /* EOF is -1, and hence we can't push value 255 in this way */
+                /* EOF is -1, and hence we can't push value 255 in this way if char is signed */
                 assert_se(ungetc(c, f) != EOF || c == EOF);
                 assert_se(c == EOF || safe_fgetc(f, &c) == 1);
                 assert_se(c == chars[i]);
@@ -654,6 +658,8 @@ static void test_fgetc(void) {
         assert_se(safe_fgetc(f, &c) == 0);
 }
 
+#pragma GCC diagnostic pop
+
 static const char buffer[] =
         "Some test data\n"
         "루Non-ascii chars: ąę„”\n"
@@ -711,7 +717,7 @@ static void test_read_line_one_file(FILE *f) {
         line = mfree(line);
 
         /* read_line() stopped when it hit the limit, that means when we continue reading we'll read at the first
-         * character after the previous limit. Let's make use of tha to continue our test. */
+         * character after the previous limit. Let's make use of that to continue our test. */
         assert_se(read_line(f, 1024, &line) == 62 && streq(line, "line that is supposed to be truncated, because it is so long"));
         line = mfree(line);
 
@@ -721,7 +727,7 @@ static void test_read_line_one_file(FILE *f) {
 static void test_read_line(void) {
         _cleanup_fclose_ FILE *f = NULL;
 
-        f = fmemopen((void*) buffer, sizeof(buffer), "re");
+        f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "re");
         assert_se(f);
 
         test_read_line_one_file(f);
@@ -753,7 +759,11 @@ static void test_read_line3(void) {
         assert_se(f);
 
         r = read_line(f, LINE_MAX, &line);
-        assert_se((size_t) r == strlen(line) + 1);
+        assert_se(r >= 0);
+        if (r == 0)
+                assert_se(line && isempty(line));
+        else
+                assert_se((size_t) r == strlen(line) + 1);
         assert_se(read_line(f, LINE_MAX, NULL) == 0);
 }
 
@@ -782,7 +792,7 @@ static void test_read_line4(void) {
                 _cleanup_fclose_ FILE *f = NULL;
                 _cleanup_free_ char *s = NULL;
 
-                assert_se(f = fmemopen((void*) eof_endings[i].string, eof_endings[i].length, "r"));
+                assert_se(f = fmemopen_unlocked((void*) eof_endings[i].string, eof_endings[i].length, "r"));
 
                 r = read_line(f, (size_t) -1, &s);
                 assert_se((size_t) r == eof_endings[i].length);
@@ -803,7 +813,7 @@ static void test_read_nul_string(void) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_free_ char *s = NULL;
 
-        assert_se(f = fmemopen((void*) test, sizeof(test)-1, "r"));
+        assert_se(f = fmemopen_unlocked((void*) test, sizeof(test)-1, "r"));
 
         assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 13 && streq_ptr(s, "string nr. 1"));
         s = mfree(s);