On 08/10/12 19:25, Justin Lebar wrote:
I think this fails on at least one edge case: If the file contains
only the string "__date__", then len == i == 8 and we never enter the
loop, right?  I think we in general fail to detect temporal macros at
the very end of the file, with this patch.

The solution isn't as simple as making it |i <= len|, of course,
because the end of the loop reads str[i].

Grrr, those pesky fenceposts!

Ok, after looking at it some more, I think the correct solution is to fix the table, not the code.

New patch attached.

Thanks

Andrew

>From 8805b9c30df98fb297be259700e703799b067731 Mon Sep 17 00:00:00 2001
From: Andrew Stubbs <a...@codesourcery.com>
Date: Tue, 9 Oct 2012 15:17:19 +0100
Subject: [PATCH] Detect __DATE__ and __TIME__ correctly.
To: ccache@lists.samba.org

The code to detect __DATE__ and __TIME__ was off-by-one, and therefore
totally failed to detect time macros unless by chance alignments (1 in eight
macros might be correctly aligned).

The problem is that the code expects that 'i' will point to the last
underscore, and the skip table expects 'i' to point to the point after
the end of the string. For example, if str[i] == 'E' then the skip table
moves 'i' on 3 bytes, whereas the code only works with a 2-byte skip.

I've corrected the problem by adjusting the table to match the code.

I've confirmed the tests still pass.

Signed-off-by: Andrew Stubbs <a...@codesourcery.com>
---
 macroskip.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/macroskip.h b/macroskip.h
index 1452201..791403b 100644
--- a/macroskip.h
+++ b/macroskip.h
@@ -41,9 +41,8 @@ static const uint32_t macro_skip[] = {
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
-	8,  5,  8,  8,  6,  3,  8,  8,  8,  5,  8,  8,  8,  4,  8,  8,
-	8,  8,  8,  8,  4,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  1,
-	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	8,  4,  8,  8,  5,  2,  8,  8,  8,  4,  8,  8,  8,  3,  8,  8,
+	8,  8,  8,  8,  3,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  1,
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
@@ -53,4 +52,5 @@ static const uint32_t macro_skip[] = {
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
 	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
+	8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8
 };
-- 
1.7.9.5

_______________________________________________
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache

Reply via email to