Don't use VLA's in unit tests and API examples (#3002)
MSVC doesn't support C99 VLA (variable-length array). Use fixed size arrays in API examples and use JERRY_VLA macro in unit tests to make these tests buildable on Windows too. JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu
This commit is contained in:
committed by
Robert Fancsik
parent
051febfed7
commit
9c7511221f
@@ -60,8 +60,8 @@ main (void)
|
||||
utf8_sz = jerry_get_string_size (args[0]);
|
||||
cesu8_sz = jerry_get_string_size (args[1]);
|
||||
|
||||
char string_from_utf8[utf8_sz];
|
||||
char string_from_cesu8[cesu8_sz];
|
||||
JERRY_VLA (char, string_from_utf8, utf8_sz);
|
||||
JERRY_VLA (char, string_from_cesu8, cesu8_sz);
|
||||
|
||||
jerry_string_to_char_buffer (args[0], (jerry_char_t *) string_from_utf8, utf8_sz);
|
||||
jerry_string_to_char_buffer (args[1], (jerry_char_t *) string_from_cesu8, cesu8_sz);
|
||||
@@ -85,8 +85,8 @@ main (void)
|
||||
|
||||
TEST_ASSERT (utf8_sz == cesu8_sz);
|
||||
|
||||
char string_from_utf8_string[utf8_sz];
|
||||
char string_from_cesu8_string[cesu8_sz];
|
||||
JERRY_VLA (char, string_from_utf8_string, utf8_sz);
|
||||
JERRY_VLA (char, string_from_cesu8_string, cesu8_sz);
|
||||
|
||||
jerry_string_to_utf8_char_buffer (args[0], (jerry_char_t *) string_from_utf8_string, utf8_sz);
|
||||
jerry_string_to_utf8_char_buffer (args[1], (jerry_char_t *) string_from_cesu8_string, cesu8_sz);
|
||||
@@ -108,7 +108,7 @@ main (void)
|
||||
TEST_ASSERT (cesu8_sz != utf8_sz);
|
||||
TEST_ASSERT (utf8_sz == 14 && cesu8_sz == 18);
|
||||
|
||||
char test_string[utf8_sz];
|
||||
JERRY_VLA (char, test_string, utf8_sz);
|
||||
|
||||
TEST_ASSERT (jerry_string_to_utf8_char_buffer (args[0], (jerry_char_t *) test_string, utf8_sz) == 14);
|
||||
TEST_ASSERT (!strncmp (test_string, "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 \xf0\x9d\x94\xa4", utf8_sz));
|
||||
@@ -210,7 +210,7 @@ main (void)
|
||||
/* Buffer size */
|
||||
cesu8_sz = 5;
|
||||
|
||||
char substring[cesu8_sz];
|
||||
JERRY_VLA (char, substring, cesu8_sz);
|
||||
sz = jerry_substring_to_char_buffer (args[0], 3, 8, (jerry_char_t *) substring, cesu8_sz);
|
||||
TEST_ASSERT (sz == 5);
|
||||
TEST_ASSERT (!strncmp (substring, "ascii", sz));
|
||||
@@ -238,7 +238,7 @@ main (void)
|
||||
TEST_ASSERT (cesu8_length == 15);
|
||||
TEST_ASSERT (cesu8_length == cesu8_sz);
|
||||
|
||||
char fullstring[cesu8_sz];
|
||||
JERRY_VLA (char, fullstring, cesu8_sz);
|
||||
sz = jerry_substring_to_char_buffer (args[0], 0, cesu8_length, (jerry_char_t *) fullstring, cesu8_sz);
|
||||
TEST_ASSERT (sz == 15);
|
||||
TEST_ASSERT (!strncmp (fullstring, "an ascii string", sz));
|
||||
@@ -249,7 +249,7 @@ main (void)
|
||||
args[0] = jerry_create_string ((jerry_char_t *) "0101");
|
||||
cesu8_sz = jerry_get_string_size (args[0]);
|
||||
|
||||
char number_substring[cesu8_sz];
|
||||
JERRY_VLA (char, number_substring, cesu8_sz);
|
||||
|
||||
sz = jerry_substring_to_char_buffer (args[0], 1, 3, (jerry_char_t *) number_substring, cesu8_sz);
|
||||
TEST_ASSERT (sz == 2);
|
||||
@@ -264,7 +264,7 @@ main (void)
|
||||
TEST_ASSERT (cesu8_sz == 11);
|
||||
TEST_ASSERT (cesu8_length = 7);
|
||||
|
||||
char supl_substring[cesu8_sz];
|
||||
JERRY_VLA (char, supl_substring, cesu8_sz);
|
||||
|
||||
sz = jerry_substring_to_char_buffer (args[0], 0, cesu8_length, (jerry_char_t *) supl_substring, cesu8_sz);
|
||||
TEST_ASSERT (sz == 11);
|
||||
|
||||
Reference in New Issue
Block a user