Skip to content
Snippets Groups Projects
Commit aed04e63 authored by Peter Maydell's avatar Peter Maydell Committed by Alex Bennée
Browse files

semihosting: Don't return negative values on qemu_semihosting_console_write() failure


The documentation comment for qemu_semihosting_console_write() says
 * Returns: number of bytes written -- this should only ever be short
 * on some sort of i/o error.

and the callsites rely on this.  However, the implementation code
path which sends console output to a chardev doesn't honour this,
and will return negative values on error.  Bring it into line with
the other implementation codepaths and the documentation, so that
it returns 0 on error.

Spotted by Coverity, because console_write() passes the return value
to unlock_user(), which doesn't accept a negative length.

Resolves: Coverity CID 1490288
Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
Message-Id: <20220719121110.225657-2-peter.maydell@linaro.org>
Signed-off-by: default avatarAlex Bennée <alex.bennee@linaro.org>
Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220725140520.515340-7-alex.bennee@linaro.org>
parent 93a02e82
No related branches found
No related tags found
No related merge requests found
......@@ -111,7 +111,8 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
int qemu_semihosting_console_write(void *buf, int len)
{
if (console.chr) {
return qemu_chr_write_all(console.chr, (uint8_t *)buf, len);
int r = qemu_chr_write_all(console.chr, (uint8_t *)buf, len);
return r < 0 ? 0 : r;
} else {
return fwrite(buf, 1, len, stderr);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment