From 2b0f75ca8d29c3f5d992e64e7bd04cb75062fdbb Mon Sep 17 00:00:00 2001 From: jay Date: Tue, 8 Aug 2006 22:27:15 +0000 Subject: [PATCH] Automatically verify (at compile time) that the frcode datastream cannot get desynchronised. --- locate/locatedb.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/locate/locatedb.h b/locate/locatedb.h index cb8b176..ad670e1 100644 --- a/locate/locatedb.h +++ b/locate/locatedb.h @@ -32,6 +32,19 @@ This value (which is -128) indicates that the difference is too large to fit into one byte, and a two-byte integer follows. */ #define LOCATEDB_ESCAPE 0x80 +#define LOCATEDB_ONEBYTE_MAX (127) +#define LOCATEDB_ONEBYTE_MIN (-127) + + +/* If it is ever possible to try to encode LOCATEDB_MAGIC as a + * single-byte offset, then an unfortunate length of common prefix + * will produce a spurious escape character, desynchronising the data + * stream. We use a compile-time check in the preprocessor to prevent + * this. + */ +#if LOCATEDB_ESCAPE <= LOCATEDB_ONEBYTE_MAX +#error "You have a bad combination of LOCATEDB_ESCAPE and LOCATEDB_ONEBYTE_MAX, see above" +#endif /* These are used for old, bigram-encoded databases: */ -- 2.11.4.GIT