Skip to content

Commit

Permalink
Use manual strdup, free the duplicated pshader string, simplify char …
Browse files Browse the repository at this point in the history
…assignment
  • Loading branch information
TheSpydog committed Nov 4, 2024
1 parent afc2d73 commit ce544d8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mojoshader_sdlgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,13 @@ static MOJOSHADER_sdlProgram *compile_program(
// Handle texcoord0 -> point_coord conversion
if (strstr(vshaderSource, "[[point_size]]"))
{
pshaderSource = strdup(pshader->parseData->output);
pshaderSource = (char *) ctx->malloc_fn(strlen(pshader->parseData->output) + 1, ctx->malloc_data);
if (!pshaderSource)
{
out_of_memory();
return NULL;
}
strcpy(pshaderSource, pshader->parseData->output);

// !!! FIXME: This assumes all texcoord0 attributes in the effect are
// !!! FIXME: actually point coords! It ain't necessarily so! -caleb
Expand All @@ -667,7 +673,7 @@ static MOJOSHADER_sdlProgram *compile_program(
while (spaces < 2)
if (*(ptr--) == ' ')
spaces++;
memcpy(ptr, "2", sizeof(char));
*ptr = '2';
} // while
} // if
}
Expand Down Expand Up @@ -713,6 +719,9 @@ static MOJOSHADER_sdlProgram *compile_program(
return NULL;
} // if

if (pshaderSource != pshader->parseData->output)
ctx->free_fn(ctx, pshaderSource);

return program;
} // compile_program

Expand Down

0 comments on commit ce544d8

Please sign in to comment.