On 08.02.2014 16:10, Tony Houghton wrote:
On Sat, 08 Feb 2014 15:17:09 +0100
Klaus Schmidinger <klaus.schmidin...@tvdr.de> wrote:

On 08.02.2014 14:34, Tony Houghton wrote:

The warning is justified, because if rid is 0 it's still there as an
argument, but just happens to have a value of 0. I think you can make
snprintf "consume" it without printing anything by adding %.d to the
second format string.

I'm afraid not.
If I run

#include <stdio.h>
int main(void)
{
    for (int n = 0; n < 2; n++)
        printf(n ? "'%d-%d'\n" : "'%d%.d'\n", 1, 2);
    return 0;
}

I get

'12'
'1-2'

But maybe there *is* such a format character, it just isn't "%.d".

You're right, it looks like it has to be %.s, it doesn't work with %.d.
If you used %.s you'd probably just get a type mismatch warning instead
:-(. There's nothing wrong with the way you wrote it, but I like to
enable all possible warnings and eliminate them. In this case I think
I'd just print the rid even if it's 0.

The thing is that I'd rather get rid of the RID altogether at some point,
so I wouldn't want to manifest it by printing it if it is 0 ;-).

Can you suggest a different way of causing a segfault at this point?

You could add volatile as the warning suggests. Is there a good reason
not to use abort() instead?

The idea behind this was to allow for easy backtracking in such a case.
I believe abort() wouldn't allow this, would it?

abort() does usually generate a useful core dump/stack backtrace IME.

You're right, I've changed it.

Klaus

_______________________________________________
vdr mailing list
vdr@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

Reply via email to