diff --git a/src/stralloc.c b/src/stralloc.c
index 3235b071e8ae116390a629aebc2bca52095d5a8e..4549a338bd479d6ff3bd380abe09b8679682d004 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -1697,7 +1697,7 @@ struct pike_string *new_realloc_shared_string(struct pike_string *a, INT32 size,
 
   r=begin_wide_shared_string(size,shift);
   pike_string_cpy(MKPCHARP_STR(r),a);
-  r->flags |= (a->flags & ~15);
+  r->flags |= (a->flags & STRING_CHECKED_MASK);
   r->min = a->min;
   r->max = a->max;
   free_string(a);
@@ -1870,7 +1870,7 @@ PMOD_EXPORT void set_flags_for_add( struct pike_string *ret,
                                     struct pike_string *b)
 {
   if( !b->len ) {
-    ret->flags |= aflags & ~15;
+    ret->flags |= aflags & STRING_CHECKED_MASK;
     ret->min = amin;
     ret->max = amax;
     return;
diff --git a/src/stralloc.h b/src/stralloc.h
index 299275646821bc6ff7eaa0a5e5a9e415edcdab7c..34cddba72b4152215cd861bf2c9e3d0554dc88e5 100644
--- a/src/stralloc.h
+++ b/src/stralloc.h
@@ -55,6 +55,8 @@ struct string_builder
 #define STRING_IS_LOWERCASE    32
 #define STRING_IS_UPPERCASE    64
 
+#define STRING_CHECKED_MASK (STRING_IS_UPPERCASE|STRING_IS_LOWERCASE|STRING_CONTENT_CHECKED)
+
 #define CLEAR_STRING_CHECKED(X) do{(X)->flags &= 15;}while(0)
 
 /* Flags used by string_builder_append_integer() */