From f4874705d95adfc85be535b85c9db26f5d3746f7 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Sat, 1 May 2010 22:01:28 -0700 Subject: glsl: s/sprintf/_mesa_snprintf/ --- src/mesa/shader/slang/slang_codegen.c | 2 +- src/mesa/shader/slang/slang_emit.c | 31 +++++++++++++++---------------- src/mesa/shader/slang/slang_ir.c | 8 ++++---- src/mesa/shader/slang/slang_label.c | 2 +- src/mesa/shader/slang/slang_link.c | 5 +++-- src/mesa/shader/slang/slang_print.c | 8 ++++---- src/mesa/shader/slang/slang_utility.c | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index fa79632c18..27ac1da9ad 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1560,7 +1560,7 @@ _slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun, char name[200]; prevFuncEndLabel = A->curFuncEndLabel; - sprintf(name, "__endOfFunc_%s_", (char *) fun->header.a_name); + _mesa_snprintf(name, sizeof(name), "__endOfFunc_%s_", (char *) fun->header.a_name); A->curFuncEndLabel = _slang_label_new(name); assert(A->curFuncEndLabel); diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 7c0ea0c114..974c4a3131 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -652,30 +652,30 @@ storage_annotation(const slang_ir_node *n, const struct gl_program *prog) if (st->Index >= 0) { const GLfloat *val = prog->Parameters->ParameterValues[st->Index]; if (st->Swizzle == SWIZZLE_NOOP) - sprintf(s, "{%g, %g, %g, %g}", val[0], val[1], val[2], val[3]); + _mesa_snprintf(s, sizeof(s), "{%g, %g, %g, %g}", val[0], val[1], val[2], val[3]); else { - sprintf(s, "%g", val[GET_SWZ(st->Swizzle, 0)]); + _mesa_snprintf(s, sizeof(s), "%g", val[GET_SWZ(st->Swizzle, 0)]); } } break; case PROGRAM_TEMPORARY: if (n->Var) - sprintf(s, "%s", (char *) n->Var->a_name); + _mesa_snprintf(s, sizeof(s), "%s", (char *) n->Var->a_name); else - sprintf(s, "t[%d]", st->Index); + _mesa_snprintf(s, sizeof(s), "t[%d]", st->Index); break; case PROGRAM_STATE_VAR: case PROGRAM_UNIFORM: - sprintf(s, "%s", prog->Parameters->Parameters[st->Index].Name); + _mesa_snprintf(s, sizeof(s), "%s", prog->Parameters->Parameters[st->Index].Name); break; case PROGRAM_VARYING: - sprintf(s, "%s", prog->Varying->Parameters[st->Index].Name); + _mesa_snprintf(s, sizeof(s), "%s", prog->Varying->Parameters[st->Index].Name); break; case PROGRAM_INPUT: - sprintf(s, "input[%d]", st->Index); + _mesa_snprintf(s, sizeof(s), "input[%d]", st->Index); break; case PROGRAM_OUTPUT: - sprintf(s, "output[%d]", st->Index); + _mesa_snprintf(s, sizeof(s), "output[%d]", st->Index); break; default: s[0] = 0; @@ -752,9 +752,8 @@ instruction_annotation(gl_inst_opcode opcode, char *dstAnnot, } s = (char *) malloc(len); - sprintf(s, "%s = %s %s %s %s", dstAnnot, - srcAnnot0, operator, srcAnnot1, srcAnnot2); - assert(strlen(s) < len); + _mesa_snprintf(s, len, "%s = %s %s %s %s", dstAnnot, + srcAnnot0, operator, srcAnnot1, srcAnnot2); free(dstAnnot); free(srcAnnot0); @@ -2274,11 +2273,11 @@ emit_var_decl(slang_emit_info *emitInfo, slang_ir_node *n) if (emitInfo->EmitComments) { /* emit NOP with comment describing the variable's storage location */ char s[1000]; - sprintf(s, "TEMP[%d]%s = variable %s (size %d)", - n->Store->Index, - _mesa_swizzle_string(n->Store->Swizzle, 0, GL_FALSE), - (n->Var ? (char *) n->Var->a_name : "anonymous"), - n->Store->Size); + _mesa_snprintf(s, sizeof(s), "TEMP[%d]%s = variable %s (size %d)", + n->Store->Index, + _mesa_swizzle_string(n->Store->Swizzle, 0, GL_FALSE), + (n->Var ? (char *) n->Var->a_name : "anonymous"), + n->Store->Size); emit_comment(emitInfo, s); } return NULL; diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c index 62603503dd..c223004b22 100644 --- a/src/mesa/shader/slang/slang_ir.c +++ b/src/mesa/shader/slang/slang_ir.c @@ -340,13 +340,13 @@ storage_string(const slang_ir_storage *st) assert(Elements(files) == PROGRAM_FILE_MAX); #if 0 if (st->Size == 1) - sprintf(s, "%s[%d]", files[st->File], st->Index); + _mesa_snprintf(s, "%s[%d]", files[st->File], st->Index); else - sprintf(s, "%s[%d..%d]", files[st->File], st->Index, - st->Index + st->Size - 1); + _mesa_snprintf(s, "%s[%d..%d]", files[st->File], st->Index, + st->Index + st->Size - 1); #endif assert(st->File < (GLint) (sizeof(files) / sizeof(files[0]))); - sprintf(s, "%s[%d]", files[st->File], st->Index); + _mesa_snprintf(s, sizeof(s), "%s[%d]", files[st->File], st->Index); return s; } diff --git a/src/mesa/shader/slang/slang_label.c b/src/mesa/shader/slang/slang_label.c index 225612a936..8e3a8ebc1a 100644 --- a/src/mesa/shader/slang/slang_label.c +++ b/src/mesa/shader/slang/slang_label.c @@ -37,7 +37,7 @@ _slang_label_new_unique(const char *name) free(l); return NULL; } - sprintf(l->Name, "%s_%d", name, id); + _mesa_snprintf(l->Name, strlen(name) + 10, "%s_%d", name, id); id++; l->Location = -1; } diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 47bc933971..b16778f8ad 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -370,8 +370,9 @@ link_uniform_vars(GLcontext *ctx, GLuint newSampNum = *numSamplers; if (newSampNum >= ctx->Const.MaxTextureImageUnits) { char s[100]; - sprintf(s, "Too many texture samplers (%u, max is %u)", - newSampNum, ctx->Const.MaxTextureImageUnits); + _mesa_snprintf(s, sizeof(s), + "Too many texture samplers (%u, max is %u)", + newSampNum, ctx->Const.MaxTextureImageUnits); link_error(shProg, s); return GL_FALSE; } diff --git a/src/mesa/shader/slang/slang_print.c b/src/mesa/shader/slang/slang_print.c index 3c75523c42..6b34f395fd 100644 --- a/src/mesa/shader/slang/slang_print.c +++ b/src/mesa/shader/slang/slang_print.c @@ -813,7 +813,7 @@ static const char * slang_fq_type_string(const slang_fully_specified_type *t) { static char str[1000]; - sprintf(str, "%s %s", slang_type_qual_string(t->qualifier), + _mesa_snprintf(str, sizeof(str), "%s %s", slang_type_qual_string(t->qualifier), slang_type_string(t->specifier.type)); return str; } @@ -832,9 +832,9 @@ static char * slang_var_string(const slang_variable *v) { static char str[1000]; - sprintf(str, "%s : %s", - (char *) v->a_name, - slang_fq_type_string(&v->type)); + _mesa_snprintf(str, sizeof(str), "%s : %s", + (char *) v->a_name, + slang_fq_type_string(&v->type)); return str; } #endif diff --git a/src/mesa/shader/slang/slang_utility.c b/src/mesa/shader/slang/slang_utility.c index e77404f692..c1d57409a4 100644 --- a/src/mesa/shader/slang/slang_utility.c +++ b/src/mesa/shader/slang/slang_utility.c @@ -120,7 +120,7 @@ slang_string_pushi (slang_string *self, GLint i) { char buffer[12]; - sprintf (buffer, "%d", i); + _mesa_snprintf (buffer, sizeof(buffer), "%d", i); slang_string_pushs (self, buffer, strlen (buffer)); } -- cgit v1.2.3 From a12614362a79d676eeb1c3030ed52057bcb8f4f8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 3 May 2010 13:58:51 -0600 Subject: glsl: change variable declared assertion into conditional The slang_variable::declared field originated as a debug field but can be promoted for use during sematic error checking. Fixes fd.o bug 27921. NOTE: this is a candidate for back-porting to the 7.8 stable branch. --- src/mesa/shader/slang/slang_codegen.c | 3 +-- src/mesa/shader/slang/slang_compile_variable.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/mesa/shader') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 27ac1da9ad..4b876a460c 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -4187,11 +4187,10 @@ _slang_gen_variable(slang_assemble_ctx * A, slang_operation *oper) slang_atom name = oper->var ? oper->var->a_name : oper->a_id; slang_variable *var = _slang_variable_locate(oper->locals, name, GL_TRUE); slang_ir_node *n; - if (!var) { + if (!var || !var->declared) { slang_info_log_error(A->log, "undefined variable '%s'", (char *) name); return NULL; } - assert(var->declared); n = new_var(A, var); return n; } diff --git a/src/mesa/shader/slang/slang_compile_variable.h b/src/mesa/shader/slang/slang_compile_variable.h index b4585599f2..5c9d248b35 100644 --- a/src/mesa/shader/slang/slang_compile_variable.h +++ b/src/mesa/shader/slang/slang_compile_variable.h @@ -41,7 +41,7 @@ typedef struct slang_variable_ GLuint size; /**< Variable's size in bytes */ GLboolean is_global; GLboolean isTemp; /**< a named temporary (__resultTmp) */ - GLboolean declared; /**< for debug */ + GLboolean declared; /**< has the var been declared? */ struct slang_ir_storage_ *store; /**< Storage for this var */ } slang_variable; -- cgit v1.2.3