From d290b76bb1efd352775511b6bed2bef73610a655 Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Wed, 12 Nov 2014 11:24:20 +0100
Subject: [PATCH] Fundamental properties of empty strings corrected.

An empty string:
- IS lowercase
- IS uppercase

'STRING_IS_LOWERCASE' means the same string will be returned for
lower_case(str), and 'STRING_IS_UPPERCASE' means the same string will
be returned for upper_case(str).

Having this be wrong for the empty string is not really a good idea,
since when strings are constructed using += the bits will not be set
correctly if you start with the empty string.

Also note: All code using string ranges really needs a special case
for the empty string, since its range of characters, when checked
using check_string_range, will be 0..255 (loose check), or
-MAX_INT32..MAX_INT32 (non-loose check).

This is done correctly in the 'string_has_null' function, which is
what is supposed to be used to check if strings contain null
characters.
---
 src/stralloc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/stralloc.c b/src/stralloc.c
index 69c20f0755..db28194f1c 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -2139,6 +2139,7 @@ void init_shared_string_table(void)
   base_table=xcalloc(sizeof(struct pike_string *), htable_size);
 
   empty_pike_string = make_shared_string("");
+  empty_pike_string->flags |= STRING_IS_LOWERCASE | STRING_IS_UPPERCASE;
 }
 
 #ifdef DO_PIKE_CLEANUP
-- 
GitLab