Re: [PATCH] Detect __DATE__ and __TIME__ correctly.

Andrew Stubbs <[email protected]>
Newsgroups gmane.comp.compilers.ccache
Message-ID <[email protected]>
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

_______________________________________________
ccache mailing list
[email protected]
https://lists.samba.org/mailman/listinfo/ccache
0001-Detect-__DATE__-and-__TIME__-correctly.patch (text/x-patch, 2.1 KB)
From 8805b9c30df98fb297be259700e703799b067731 Mon Sep 17 00:00:00 2001
From: Andrew Stubbs <[email protected]>
Date: Tue, 9 Oct 2012 15:17:19 +0100
Subject: [PATCH] Detect __DATE__ and __TIME__ correctly.
To: [email protected]

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 <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.