]> granicus.if.org Git - icu/commitdiff
ICU-21793 Fix ucptrietest golden diff
authorJérémy Lal <kapouer@melix.org>
Wed, 3 Nov 2021 01:31:18 +0000 (02:31 +0100)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 3 Nov 2021 22:01:41 +0000 (15:01 -0700)
icu4c/source/tools/toolutil/toolutil.cpp

index 1fc68aa69c84ff8922594bbfa08f8a1118bc63ca..a9dc37377a840aa48af5c342a29a2be2ef0813cb 100644 (file)
@@ -228,18 +228,19 @@ uprv_compareGoldenFiles(
     std::ifstream ifs(goldenFilePath, std::ifstream::in);
     int32_t pos = 0;
     char c;
-    while ((c = ifs.get()) != std::char_traits<char>::eof() && pos < bufferLen) {
+    while (ifs.get(c) && pos < bufferLen) {
         if (c != buffer[pos]) {
             // Files differ at this position
-            return pos;
+            break;
         }
         pos++;
     }
-    if (pos < bufferLen || c != std::char_traits<char>::eof()) {
-        // Files are different lengths
-        return pos;
+    if (pos == bufferLen && ifs.eof()) {
+        // Files are same lengths
+        pos = -1;
     }
-    return -1;
+    ifs.close();
+    return pos;
 }
 
 /*U_CAPI UDate U_EXPORT2