]> diplodocus.org Git - nmh/commitdiff
Fix bug where single-character headers were sometimes missed.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 13:19:56 +0000 (14:19 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 13:19:56 +0000 (14:19 +0100)
The hash function used to check if a header was of interest always used
its first three characters.  For a single-character header that third
byte wasn't particularly set and so it was pot luck if the two hashes
matched, swayed by what was previously in the format string and in the
email's headers.  Alter it to cope, including with an empty string.
Comment that it never gives 127 so leaves the last element of the
hash-table array unused.  Alter test-header-parsing to stop declaring it
expects to fail.

sbr/fmt_compile.c
test/scan/test-header-parsing

index fbb1274..b1788ab 100644 (file)
@@ -268,13 +268,15 @@ static struct colormap colortable[] = {
     { NULL,            0,      0 }
 };
 
-/* 
- * Hash function for component name.  The function should be
- * case independent and probably shouldn't involve a routine
- * call.  This function is pretty good but will not work on
- * single character component names.  
- */
-#define        CHASH(nm) (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f))
+/* Hash function for component name.  Deliberately avoids a function
+ * call.  Is case independent.  Covers interval [0, 126] so never uses
+ * the last element of wantcomp[]. This function is "pretty good". */
+#define CHASH(nm) ( \
+        (( \
+            ((nm)[0]) - ((nm)[0] ? ((nm)[1]) : 0) \
+        ) & 0x1f) + \
+        ((nm[1]) ? (((nm)[2]) & 0x5f) : 0) \
+    )
 
 /*
  * Find a component in the hash table.
index 752fdb9..093d677 100755 (executable)
@@ -25,6 +25,6 @@ sed 's/.*://' "$mail" >"$expected"
 f="`sed 's/:.*/}/; s/^/%{/' "$mail"`"
 run_prog scan -forma "$f" -file "$mail" >"$actual" ||
 exit 1
-check "$expected" "$actual" expectfail
+check "$expected" "$actual"
 
 exit $failed