From 4c7f6f212eca77c2aae3d4bbc9b6be7f683cf260 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 9 Oct 2011 22:41:07 -0700 Subject: * lib.h (wli, lit_noex): We need null characters on both ends so that this hack is correct for null strings. When recovering the wchar_t pointer from a null literal object, we wil increment unconditionally, since it always points to a null character. We end up skipping past null terminator #1, but safely landing on #2. --- ChangeLog | 8 ++++++++ lib.h | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f7588f4..d94cf00b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-09 Kaz Kylheku + + * lib.h (wli, lit_noex): We need null characters on both ends + so that this hack is correct for null strings. When recovering + the wchar_t pointer from a null literal object, we wil increment + unconditionally, since it always points to a null character. + We end up skipping past null terminator #1, but safely landing on #2. + 2011-10-09 Kaz Kylheku Following up to previous commit's TODO. diff --git a/lib.h b/lib.h index 26bd1003..eb42e96c 100644 --- a/lib.h +++ b/lib.h @@ -191,7 +191,7 @@ INLINE type_t type(val obj) typedef struct wli wchli_t; #if LIT_ALIGN < 4 -#define wli(lit) ((const wchli_t *) L ## "\0" lit) +#define wli(lit) ((const wchli_t *) L"\0" L ## lit L"\0") #else #define wli(lit) ((const wchli_t *) L ## lit) #endif @@ -235,7 +235,7 @@ INLINE val chr(wchar_t ch) } #if LIT_ALIGN < 4 -#define lit_noex(strlit) ((obj_t *) ((cnum) (L ## "\0" L ## strlit + 1) | TAG_LIT)) +#define lit_noex(strlit) ((obj_t *) ((cnum) (L"\0" L ## strlit L"\0" + 1) | TAG_LIT)) #else #define lit_noex(strlit) ((obj_t *) ((cnum) (L ## strlit) | TAG_LIT)) #endif -- cgit v1.2.3