All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: Keith Packard <keithp@keithp.com>,
	Riku Voipio <riku.voipio@iki.fi>,
	Richard Henderson <richard.henderson@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Laurent Vivier <laurent@vivier.eu>,
	"open list:ARM TCG CPUs" <qemu-arm@nongnu.org>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PULL v2 11/14] semihosting: add qemu_semihosting_console_inc for SYS_READC
Date: Fri, 24 Jan 2020 12:58:40 +0000	[thread overview]
Message-ID: <CAFEAcA-os-6iWZ-ucM-VUECyf8sn-xoANHCqJqtSyuttgZY23A@mail.gmail.com> (raw)
In-Reply-To: <20200109141858.14376-12-alex.bennee@linaro.org>

On Thu, 9 Jan 2020 at 14:19, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> From: Keith Packard <keithp@keithp.com>
>
> Provides a blocking call to read a character from the console using
> semihosting.chardev, if specified. This takes some careful command
> line options to use stdio successfully as the serial ports, monitor
> and semihost all want to use stdio. Here's a sample set of command
> line options which share stdio between semihost, monitor and serial
> ports:

Hi; Coverity has some complaints about this code, and
specifically the use of getchar():

> +/*
> + * For linux-user we can safely block. However as we want to return as
> + * soon as a character is read we need to tweak the termio to disable
> + * line buffering. We restore the old mode afterwards in case the
> + * program is expecting more normal behaviour. This is slow but
> + * nothing using semihosting console reading is expecting to be fast.
> + */
> +target_ulong qemu_semihosting_console_inc(CPUArchState *env)
> +{
> +    uint8_t c;
> +    struct termios old_tio, new_tio;
> +
> +    /* Disable line-buffering and echo */
> +    tcgetattr(STDIN_FILENO, &old_tio);
> +    new_tio = old_tio;
> +    new_tio.c_lflag &= (~ICANON & ~ECHO);
> +    tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
> +
> +    c = getchar();

CID 1412794 points out that this assigns the result
of getchar() to a uint8_t, which drops the distinction
between EOF and a legitimate byte.
CID 1412795 is then kind of a run-on error from that,
complaining that the int result from getchar() is
truncated before returning it.

I'm not sure what we should do with EOF, but presumably
we should handle it in some way.

thanks
-- PMM


  reply	other threads:[~2020-01-24 12:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 14:18 [PULL v2 00/14] testing fixes and semihosting console support Alex Bennée
2020-01-09 14:18 ` [PULL v2 01/14] hw/i386/x86-iommu: Add missing stubs Alex Bennée
2020-01-09 14:18 ` [PULL v2 02/14] tests/vm: update openbsd to release 6.6 Alex Bennée
2020-01-09 14:18 ` [PULL v2 03/14] freebsd: use python37 Alex Bennée
2020-01-09 14:18 ` [PULL v2 04/14] travis.yml: avocado: Print logs of non-pass tests only Alex Bennée
2020-01-09 14:18 ` [PULL v2 05/14] travis.yml: Detach build and test steps Alex Bennée
2020-01-09 14:18 ` [PULL v2 06/14] travis.yml: duplicate before_script for MacOSX Alex Bennée
2020-01-09 14:18 ` [PULL v2 07/14] travis.yml: install homebrew python for OS X Alex Bennée
2020-01-09 14:18 ` [PULL v2 08/14] testing: don't nest build for fp-test Alex Bennée
2020-01-09 14:18 ` [PULL v2 09/14] target/arm: remove unused EXCP_SEMIHOST leg Alex Bennée
2020-01-09 14:18 ` [PULL v2 10/14] target/arm: only update pc after semihosting completes Alex Bennée
2020-01-09 14:18 ` [PULL v2 11/14] semihosting: add qemu_semihosting_console_inc for SYS_READC Alex Bennée
2020-01-24 12:58   ` Peter Maydell [this message]
2020-01-24 18:45     ` Keith Packard via
2020-01-09 14:18 ` [PULL v2 12/14] tests/tcg: add a dumb-as-bricks semihosting console test Alex Bennée
2020-01-09 14:18 ` [PULL v2 13/14] tests/tcg: extract __semi_call into a header and expand Alex Bennée
2020-01-09 14:18 ` [PULL v2 14/14] tests/tcg: add user version of dumb-as-bricks semiconsole test Alex Bennée
2020-01-10 14:12 ` [PULL v2 00/14] testing fixes and semihosting console support Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFEAcA-os-6iWZ-ucM-VUECyf8sn-xoANHCqJqtSyuttgZY23A@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=keithp@keithp.com \
    --cc=laurent@vivier.eu \
    --cc=pbonzini@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.