misc: cr_str_to_evr(): Return NULL instead of "0" for bad (non-numerical) epoch
authorTomas Mlcoch <tmlcoch@redhat.com>
Fri, 4 Sep 2015 07:50:41 +0000 (09:50 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Fri, 4 Sep 2015 07:55:56 +0000 (09:55 +0200)
Epoch which is defined and isn't an integer number is obviously a bad
epoch and cr_str_to_evr should let us know about such epoch.

See: https://lists.fedoraproject.org/pipermail/devel/2015-September/214019.html

Whole thread:
https://lists.fedoraproject.org/pipermail/devel/2015-August/213132.html

src/misc.c
tests/test_misc.c

index 90e9d9c80d2c85824e7b0c0433b9e8661cecefdc..ed0582797f24b8339ea25ae0df787921a399da40 100644 (file)
@@ -94,6 +94,7 @@ cr_str_to_evr(const char *string, GStringChunk *chunk)
 
 
     // Epoch
+    gboolean bad_epoch = FALSE;
 
     ptr = strstr(string, ":");
     if (ptr) {
@@ -109,12 +110,14 @@ cr_str_to_evr(const char *string, GStringChunk *chunk)
                     evr->epoch = g_strndup(string, len);
                 }
             }
+        } else { // Bad (non-numerical) epoch
+            bad_epoch = TRUE;
         }
     } else { // There is no epoch
         ptr = (char*) string-1;
     }
 
-    if (!evr->epoch) {
+    if (!evr->epoch && !bad_epoch) {
         if (chunk) {
             evr->epoch = g_string_chunk_insert_const(chunk, "0");
         } else {
index f83a28de2c82d593010556207e2de16cb3da6a9d..9d528c70e02cc107744a1681236f18cb039187d3 100644 (file)
@@ -160,13 +160,13 @@ test_cr_str_to_evr(void)
     cr_evr_free(evr);
 
     evr = cr_str_to_evr("-:", NULL);
-    g_assert_cmpstr(evr->epoch, ==, "0");
+    g_assert_cmpstr(evr->epoch, ==, NULL);
     g_assert_cmpstr(evr->version, ==, "");
     g_assert_cmpstr(evr->release, ==, NULL);
     cr_evr_free(evr);
 
     evr = cr_str_to_evr("foo:bar", NULL);
-    g_assert_cmpstr(evr->epoch, ==, "0");
+    g_assert_cmpstr(evr->epoch, ==, NULL);
     g_assert_cmpstr(evr->version, ==, "bar");
     g_assert_cmpstr(evr->release, ==, NULL);
     cr_evr_free(evr);
@@ -295,13 +295,13 @@ test_cr_str_to_evr_with_chunk(void)
     g_free(evr);
 
     evr = cr_str_to_evr("-:", chunk);
-    g_assert_cmpstr(evr->epoch, ==, "0");
+    g_assert_cmpstr(evr->epoch, ==, NULL);
     g_assert_cmpstr(evr->version, ==, "");
     g_assert_cmpstr(evr->release, ==, NULL);
     g_free(evr);
 
     evr = cr_str_to_evr("foo:bar", chunk);
-    g_assert_cmpstr(evr->epoch, ==, "0");
+    g_assert_cmpstr(evr->epoch, ==, NULL);
     g_assert_cmpstr(evr->version, ==, "bar");
     g_assert_cmpstr(evr->release, ==, NULL);
     g_free(evr);