Re: wined3d: fix a compiler warning
Hello Austin, On Tue, Jun 23, 2009 at 12:47:18AM -0500, Austin English wrote:
Okay'ed by Henri
are you reinventing strcpy?
diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c index 44b4fce..f759372 100644 --- a/dlls/wined3d/arb_program_shader.c +++ b/dlls/wined3d/arb_program_shader.c @@ -922,11 +922,11 @@ static void shader_arb_get_register_name(const struct wined3d_shader_instruction { if(This->baseShader.reg_maps.shader_version.major < 3) { - sprintf(register_name, ctx->texcrd_output[reg->idx]); + sprintf(register_name, "%s", ctx->texcrd_output[reg->idx]); } else { - sprintf(register_name, ctx->vs_output[reg->idx]); + sprintf(register_name, "%s", ctx->vs_output[reg->idx]); } } break;
bye michael
On Tue, Jun 23, 2009 at 3:58 AM, Michael Stefaniuc<mstefani(a)redhat.de> wrote:
Hello Austin,
are you reinventing strcpy?
We do this elsewhere throughout the source. It prevents possible crashes/security vulnerabilities, as well as this warning: arb_program_shader.c: In function ‘shader_arb_get_register_name’: arb_program_shader.c:931: warning: format not a string literal and no format arguments arb_program_shader.c:935: warning: format not a string literal and no format arguments -- -Austin
On Wed, Jun 24, 2009 at 03:43, Austin English<austinenglish(a)gmail.com> wrote:
On Tue, Jun 23, 2009 at 3:58 AM, Michael Stefaniuc<mstefani(a)redhat.de> wrote:
Hello Austin,
are you reinventing strcpy?
We do this elsewhere throughout the source. It prevents possible crashes/security vulnerabilities, as well as this warning: arb_program_shader.c: In function ‘shader_arb_get_register_name’: arb_program_shader.c:931: warning: format not a string literal and no format arguments arb_program_shader.c:935: warning: format not a string literal and no format arguments
-- -Austin
I think what Michael meant is that sprintf(a, "%s", b); is doing exactly the same thing as strcpy(a, b); in a less efficient way. -- Pierre "delroth" Bourdon <delroth(a)gmail.com> Étudiant à l'EPITA / Student at EPITA
On Tue, Jun 23, 2009 at 9:45 PM, Pierre Bourdon<delroth(a)gmail.com> wrote:
On Wed, Jun 24, 2009 at 03:43, Austin English<austinenglish(a)gmail.com> wrote:
On Tue, Jun 23, 2009 at 3:58 AM, Michael Stefaniuc<mstefani(a)redhat.de> wrote:
Hello Austin,
are you reinventing strcpy?
We do this elsewhere throughout the source. It prevents possible crashes/security vulnerabilities, as well as this warning: arb_program_shader.c: In function ‘shader_arb_get_register_name’: arb_program_shader.c:931: warning: format not a string literal and no format arguments arb_program_shader.c:935: warning: format not a string literal and no format arguments
-- -Austin
I think what Michael meant is that sprintf(a, "%s", b);
is doing exactly the same thing as strcpy(a, b);
in a less efficient way.
-- Pierre "delroth" Bourdon <delroth(a)gmail.com> Étudiant à l'EPITA / Student at EPITA
Ah, my mistake. Point taken, resent patch. -- -Austin
Pierre Bourdon wrote:
On Wed, Jun 24, 2009 at 03:43, Austin English<austinenglish(a)gmail.com> wrote:
On Tue, Jun 23, 2009 at 3:58 AM, Michael Stefaniuc<mstefani(a)redhat.de> wrote:
Hello Austin,
are you reinventing strcpy? We do this elsewhere throughout the source. It prevents possible crashes/security vulnerabilities, as well as this warning: arb_program_shader.c: In function ‘shader_arb_get_register_name’: arb_program_shader.c:931: warning: format not a string literal and no format arguments arb_program_shader.c:935: warning: format not a string literal and no format arguments
-- -Austin
I think what Michael meant is that sprintf(a, "%s", b);
is doing exactly the same thing as strcpy(a, b); Right, that's what I meant.
in a less efficient way. I'm not that much concerned about efficiency as the compiler will optimize it. But a strcpy is definitely easier to read.
bye michael
2009/6/24 Michael Stefaniuc <mstefani(a)redhat.com>:
Pierre Bourdon wrote:
I think what Michael meant is that sprintf(a, "%s", b);
is doing exactly the same thing as strcpy(a, b);
Right, that's what I meant.
in a less efficient way. I'm not that much concerned about efficiency as the compiler will optimize it. But a strcpy is definitely easier to read.
I tend to assume that the compiler is an idiot that doesn't know a thing about optimisation, but that's me (e.g. using fputs for printing a string constant instead of fprintf). I find it makes for more readable/lean code.
Ben Klein wrote:
2009/6/24 Michael Stefaniuc <mstefani(a)redhat.com>:
Pierre Bourdon wrote:
I think what Michael meant is that sprintf(a, "%s", b);
is doing exactly the same thing as strcpy(a, b); Right, that's what I meant.
in a less efficient way. I'm not that much concerned about efficiency as the compiler will optimize it. But a strcpy is definitely easier to read.
I tend to assume that the compiler is an idiot that doesn't know a thing about optimisation, but that's me (e.g. using fputs for printing Nope, compiler are better than most humans at optimizations. Programmers should focus on using good data structures and algorithms and write readable code.
a string constant instead of fprintf). I find it makes for more readable/lean code. sprintf/strcpy is a no-brainer.
fprintf/fputs is a prime example of a grown and inconsistent API! To decide if using fputs is cleaner and easier to read really depends on the context; and example where keeping the fprint is easier to read would be something like: fprintf(fd, format1, ...); fprintf(fd, format2, ...); fprintf(fd, format3, ...); fprintf(fd, format4, ...); fprintf(fd, format5, ...); fputs(string, fd): fprintf(fd, format6, ...); fprintf(fd, format7, ...); fprintf(fd, format8, ...); fprintf(fd, format9, ...); fprintf(fd, format10, ...); Note the swapped source and destination in fputs in regards to fprintf. bye michael
participants (5)
-
Austin English -
Ben Klein -
Michael Stefaniuc -
Michael Stefaniuc -
Pierre Bourdon