From 9fe02f436f9ac5441257943b27d26948ab957e59 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 3 Feb 2009 04:10:50 -0500 Subject: [PATCH] Added StrDup(). --- mojoshader.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 97618b03..83f85200 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -265,6 +265,15 @@ static inline void *Malloc(Context *ctx, const size_t len) return retval; } // Malloc +static inline char *StrDup(Context *ctx, const char *str) +{ + char *retval = (char *) Malloc(ctx, strlen(str) + 1); + if (retval == NULL) + out_of_memory(ctx); + else + strcpy(retval, str); + return retval; +} // StrDup static inline void Free(Context *ctx, void *ptr) { @@ -428,8 +437,8 @@ static int output_line(Context *ctx, const char *fmt, ...) { OutputListNode *item = NULL; - if (isfail(ctx)) - return FAIL; // we failed previously, don't go on... + if (isfail(ctx) || ctx->out_of_memory) + return; // we failed previously, don't go on... char *scratch = get_scratch_buffer(ctx); @@ -6944,10 +6953,9 @@ static MOJOSHADER_uniform *build_uniforms(Context *ctx) { const char *name = ctx->profile->get_const_array_varname(ctx, var->index, var->count); - char *namecpy = (char *) Malloc(ctx, strlen(name) + 1); + char *namecpy = StrDup(ctx, name); if (namecpy != NULL) { - strcpy(namecpy, name); wptr->type = MOJOSHADER_UNIFORM_FLOAT; wptr->index = var->index; wptr->array_count = var->count;