Click here to Skip to main content
14,390,083 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello All,

I encountered a bug as below:

    else if (r_bytes == -1)
It looks like the following line is intended to be executed as (*(*__stdout())->_p)++, but C++ operator precedence rules mean it will be executed as *((*__stdout())->_p++). Either this, or the * is unnecessary.
CID 11299 (#2 of 2): Incorrect pointer increment (NO_EFFECT)no_effect_deref: The dereference in (int)*(*__stdout())->_p++ has no effect.
no_effect_deref: The dereference in *(*__stdout())->_p++ has no effect.
            return false;

On running a static code check i found that the warning the tool gave was "
Incorrect pointer increment (NO_EFFECT)no_effect_deref: The dereference in (int)*(*__stdout())->_p++ has no effect

I dint understand what it meant to say. Does putchar increment the stdout buffer?

Any help would be appreciated

What I have tried:

Explored the workings of putchar, but could not find its relation with stdout
Updated 4-Oct-19 7:51am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Does putchar increment the stdout buffer?
Yes, as do any of the standard functions that output text. However, since this is part of the C run time library it should not be anything you need to worry about.

If you are worried then it is easy to simulate the offending code.
Rahul VB 4-Oct-19 17:26pm
Hello Sir,

I would request you to let me know which code or possible fix can be used to justify that the bug can be ignored.Because we also need to write a unit test to prove that what ever is our analysis is correct.

After referencing to multiple sites , i see that using any function like putc and writing to stdout should solve the problem.

Is my understanding correct? Because somehow if i can prove that stdout buffer is incremented using putchar, then i can provide a fix.

Richard MacCutchan 5-Oct-19 4:15am
There is no bug, so nothing to fix.
Rate this:
Please Sign up or sign in to vote.

Solution 2

putchar(int) is equivalent to putc(int, stdout). Furthermore, putc(int, FILE *) is equivalent to fputc(int, FILE *), but may be implemented as a macro.

In this case, it would appear that putchar and putc are both implemented as macros. As is often the case, the implementers of the C standard lib, have used their knowledge of the internals of a FILE * object to implement putc, and they usually have good reasons for doing things with standard lib objects (like a FILE *), that a programmer would normally avoid. This does mean that analysis tools might report issues with the expanded macro, but they can normally be ignored. If the issue goes away if you replace putchar('+') with fputc('+', stdout), then this is one of those cases where you can safely ignore the warning from the analysis tool.
Rahul VB 4-Oct-19 17:27pm
Hello Sir,

Thanks for the solution. So does this mean that using fputc will not increment stdout?


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100