On Fri, 30 Nov 2018 at 15:31, Peter Maydell <[email protected]> wrote:
>
> The load_image() function is deprecated, as it does not let the
> caller specify how large the buffer to read the file into is.
> Use the glib g_file_get_contents() function instead, which does
> the whole "allocate memory for the file and read it in" operation.
>
> Signed-off-by: Peter Maydell <[email protected]>
> ---

> -        initrd_size = get_image_size(initrd_filename);
> -        if (initrd_size < 0) {
> +        if (!g_file_get_contents(initrd_filename, &initrd_data,
> +                                 &initrd_size, &gerr)) {
>              fprintf(stderr, "qemu: error reading initrd %s: %s\n",
> -                    initrd_filename, strerror(errno));
> +                    initrd_filename, gerr->message);
>              exit(1);
> -        } else if (initrd_size >= initrd_max) {
> +        }
> +        if (initrd_size >= initrd_max) {
>              fprintf(stderr, "qemu: initrd is too large, cannot support."
> -                    "(max: %"PRIu32", need %"PRId64")\n", initrd_max, 
> initrd_size);
> +                    "(max: %"PRIu32", need %"PRId64")\n",
> +                    initrd_max, initrd_size);

patchew reports that this introduces a format string
error on 32-bit hosts:

/tmp/qemu-test/src/hw/i386/pc.c: In function 'load_linux':
/tmp/qemu-test/src/hw/i386/pc.c:983:29: error: format '%lld' expects
argument of type 'long long int', but argument 4 has type 'gsize {aka
unsigned int}' [-Werror=format=]
             fprintf(stderr, "qemu: initrd is too large, cannot support."
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The underlying problem here is glib's weird insistance
on using its own types, which then interact badly
with everything else that's using standard POSIX types :-(

thanks
-- PMM

Reply via email to