giochannel: Clarify assertions in g_io_channel_write_chars()
How the assertions handled the case of buf != NULL && count == -1
and
buf == NULL && count == -1
were a bit fragile.
In the former case, the strlen (buf)
was assigned to count
, which is
signed. If, somehow, buf
was huge, count
would end up wrapping
around to a negative number. Avoid that by assigning directly to
count_unsigned
.
In the latter case, count_unsigned
would be set to -1
which would
wrap around. The error would then be caught by the precondition on buf != NULL
, but it seems like that could have been a happy accident rather
than something intentional. Change it to an explicit precondition which
only allows buf == NULL
iff count == 0
.
Spotted while reading through static analysis issues, although the analyser didn’t explicitly flag this up as an issue.
Signed-off-by: Philip Withnall pwithnall@endlessos.org