Skip to content

Commit 1ad8169

Browse files
committed
fix uninitialized values in shader json parsing
1 parent 56ea4d2 commit 1ad8169

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

shader.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ SDL_GPUShader* load_shader(SDL_GPUDevice* device, const char* name)
5454
return NULL;
5555
}
5656
jsmn_parser json_parser;
57-
jsmntok_t json_tokens[9];
57+
jsmntok_t json_tokens[128] = {0};
5858
jsmn_init(&json_parser);
59-
if (jsmn_parse(&json_parser, shader_json_data, shader_json_size, json_tokens, 9) <= 0)
59+
int tokens = jsmn_parse(&json_parser, shader_json_data, shader_json_size, json_tokens, 128);
60+
if (tokens <= 0)
6061
{
6162
SDL_Log("Failed to parse json: %s", shader_json_path);
6263
return NULL;
6364
}
6465
SDL_GPUShaderCreateInfo info = {0};
65-
for (int i = 1; i < 9; i += 2)
66+
for (int i = 1; i < tokens; i += 2)
6667
{
6768
if (json_tokens[i].type != JSMN_STRING)
6869
{
@@ -164,15 +165,16 @@ SDL_GPUComputePipeline* load_compute_pipeline(SDL_GPUDevice* device, const char*
164165
return NULL;
165166
}
166167
jsmn_parser json_parser;
167-
jsmntok_t json_tokens[19];
168+
jsmntok_t json_tokens[128] = {0};
168169
jsmn_init(&json_parser);
169-
if (jsmn_parse(&json_parser, shader_json_data, shader_json_size, json_tokens, 19) <= 0)
170+
int tokens = jsmn_parse(&json_parser, shader_json_data, shader_json_size, json_tokens, 128);
171+
if (tokens <= 0)
170172
{
171173
SDL_Log("Failed to parse json: %s", shader_json_path);
172174
return NULL;
173175
}
174176
SDL_GPUComputePipelineCreateInfo info = {0};
175-
for (int i = 1; i < 19; i += 2)
177+
for (int i = 1; i < tokens; i += 2)
176178
{
177179
if (json_tokens[i].type != JSMN_STRING)
178180
{

0 commit comments

Comments
 (0)