diff --git a/src/stralloc.c b/src/stralloc.c
index 0b7dd797812947ab29a149032d50f08384f9b0a2..1098ff59a6b3b97897b7f82c8a707dd234c02a77 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -2054,7 +2054,7 @@ PMOD_EXPORT void set_flags_for_add( struct pike_string *ret,
     ret->max = amax;
     return;
   }
-  if( (aflags & STRING_CONTENT_CHECKED) && (b->flags & STRING_CONTENT_CHECKED) )
+  if( aflags & b->flags & STRING_CONTENT_CHECKED )
   {
     ret->min = MIN( amin, b->min );
     ret->max = MAX( amax, b->max );
@@ -2063,7 +2063,7 @@ PMOD_EXPORT void set_flags_for_add( struct pike_string *ret,
   else
     ret->flags &= ~STRING_CONTENT_CHECKED;
 
-  ret->flags = ~(STRING_IS_LOWERCASE | STRING_IS_UPPERCASE) |
+  ret->flags = (ret->flags & ~(STRING_IS_LOWERCASE | STRING_IS_UPPERCASE)) |
     (aflags & b->flags);
 }