Skip to content

Commit 218d8c2

Browse files
committed
Add a limit assert.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent a5143e1 commit 218d8c2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ typedef struct
676676

677677
/**
678678
* Identifier for ecma-string's actual data container
679+
*
680+
* Important: ECMA_STRING_CONTAINER__MAX must be updated
681+
* below if a new constant is appended to this list
679682
*/
680683
typedef enum
681684
{
@@ -689,6 +692,11 @@ typedef enum
689692
ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< the ecma-string is equal to one of external magic strings */
690693
} ecma_string_container_t;
691694

695+
/**
696+
* Maximum value of ecma string container types.
697+
*/
698+
#define ECMA_STRING_CONTAINER__MAX ECMA_STRING_CONTAINER_MAGIC_STRING_EX
699+
692700
/**
693701
* Mask for getting the container of a string.
694702
*/

jerry-core/ecma/base/ecma-helpers-string.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ JERRY_STATIC_ASSERT ((int32_t) ECMA_STRING_MAX_CONCATENATION_LENGTH ==
5252
JERRY_STATIC_ASSERT (ECMA_STRING_CONTAINER_MASK + 1 == ECMA_STRING_REF_ONE,
5353
ecma_string_ref_counter_should_start_after_the_container_field);
5454

55+
/**
56+
* The ecma string container types must be lower than the container mask.
57+
*/
58+
JERRY_STATIC_ASSERT (ECMA_STRING_CONTAINER_MASK >= ECMA_STRING_CONTAINER__MAX,
59+
ecma_string_container_types_must_be_lower_than_the_container_mask);
60+
5561
/**
5662
* The ecma string ref and container fields should fill the 16 bit field.
5763
*/
@@ -506,10 +512,10 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
506512
case ECMA_STRING_CONTAINER_MAGIC_STRING_EX:
507513
{
508514
/* only the string descriptor itself should be freed */
515+
break;
509516
}
510517
}
511518

512-
513519
ecma_dealloc_string (string_p);
514520
} /* ecma_deref_ecma_string */
515521

0 commit comments

Comments
 (0)