]> git.notmuchmail.org Git - notmuch/commitdiff
Fix timestamp generation to avoid overflowing the term limit
authorCarl Worth <cworth@cworth.org>
Sun, 25 Oct 2009 05:10:03 +0000 (22:10 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 25 Oct 2009 05:10:03 +0000 (22:10 -0700)
The previous code was only correct as long as the timestamp prefix
was only a single character. But with the recent change to a
multi-character prefix, this broke. So fix it now.

database.cc

index c470cc34977c17beff7d152f78c5f1ac975cefd2..3d9672707b20a6213dc00cf4f83404da03508d5b 100644 (file)
@@ -542,11 +542,12 @@ find_timestamp_document (notmuch_database_t *notmuch, const char *db_key,
 static char *
 timestamp_db_key (const char *key)
 {
-    if (strlen (key) + 1 > NOTMUCH_TERM_MAX) {
+    int term_len = strlen (_find_prefix ("timestamp")) + strlen (key);
+
+    if (term_len > NOTMUCH_TERM_MAX)
        return notmuch_sha1_of_string (key);
-    } else {
+    else
        return strdup (key);
-    }
 }
 
 notmuch_status_t