From: Eric Biggers <ebiggers@kernel.org>
To: Luca Boccassi <luca.boccassi@gmail.com>
Cc: linux-fscrypt@vger.kernel.org
Subject: Re: [fsverity-utils PATCH v2 2/2] Allow to build and run sign/digest on Windows
Date: Thu, 17 Dec 2020 11:20:09 -0800 [thread overview]
Message-ID: <X9uvac1VKpuvZ68B@sol.localdomain> (raw)
In-Reply-To: <73c70f8bcb6632ab3e161d9b0263bc1563e96b34.camel@gmail.com>
On Thu, Dec 17, 2020 at 07:12:06PM +0000, Luca Boccassi wrote:
>
> I get the following warning with the mingw build now:
>
> lib/utils.c: In function ‘xmalloc’:
> lib/utils.c:23:25: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘size_t’ {aka ‘long long unsigned int’} [-Wformat=]
> libfsverity_error_msg("out of memory (tried to allocate %" SIZET_PF " bytes)",
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> size);
> ~~~~
> In file included from lib/../common/win32_defs.h:24,
> from lib/../common/common_defs.h:18,
> from lib/lib_private.h:15,
> from lib/utils.c:12:
> /usr/share/mingw-w64/include/inttypes.h:94:20: note: format string is defined here
> #define PRIu64 "I64u"
> AR libfsverity.a
> CC lib/sign_digest.shlib.o
> CC lib/compute_digest.shlib.o
> CC lib/hash_algs.shlib.o
> CC lib/utils.shlib.o
> lib/utils.c: In function ‘xmalloc’:
> lib/utils.c:23:25: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘size_t’ {aka ‘long long unsigned int’} [-Wformat=]
> libfsverity_error_msg("out of memory (tried to allocate %" SIZET_PF " bytes)",
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> size);
> ~~~~
> In file included from lib/../common/win32_defs.h:24,
> from lib/../common/common_defs.h:18,
> from lib/lib_private.h:15,
> from lib/utils.c:12:
> /usr/share/mingw-w64/include/inttypes.h:94:20: note: format string is defined here
> #define PRIu64 "I64u"
>
>
> But, honestly, it seems harmless to me. If someone on Windows is trying
> to get a digest and don't have memory to do it, they'll have bigger
> problems to worry about than knowing how much it was requested. I'll
> send a v3 with your suggested changes. As far as I can read online,
> handling %zu in a cross compatible way is like the number one
> annoyance.
>
It needs to compile without warnings, otherwise new warnings won't be noticed.
I think that if the MinGW printf is used (by defining _GNU_SOURCE), then %zu
would just work as-is. That's what I do in another project. Try:
diff --git a/Makefile b/Makefile
index cc62818..44aee92 100644
--- a/Makefile
+++ b/Makefile
@@ -52,7 +52,7 @@ override CFLAGS := -Wall -Wundef \
$(call cc-option,-Wvla) \
$(CFLAGS)
-override CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 $(CPPFLAGS)
+override CPPFLAGS := -Iinclude -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE $(CPPFLAGS)
ifneq ($(V),1)
QUIET_CC = @echo ' CC ' $@;
diff --git a/common/win32_defs.h b/common/win32_defs.h
index e13938a..3b0d908 100644
--- a/common/win32_defs.h
+++ b/common/win32_defs.h
@@ -23,12 +23,6 @@
#include <stdint.h>
#include <inttypes.h>
-#ifdef _WIN64
-# define SIZET_PF PRIu64
-#else
-# define SIZET_PF PRIu32
-#endif
-
#ifndef ENOPKG
# define ENOPKG 65
#endif
@@ -37,6 +31,11 @@
# define __cold
#endif
+#ifndef __printf
+# define __printf(fmt_idx, vargs_idx) \
+ __attribute__((format(gnu_printf, fmt_idx, vargs_idx)))
+#endif
+
typedef __signed__ char __s8;
typedef unsigned char __u8;
typedef __signed__ short __s16;
@@ -52,10 +51,6 @@ typedef __u32 __be32;
typedef __u64 __le64;
typedef __u64 __be64;
-#else
-
-#define SIZET_PF "zu"
-
#endif /* _WIN32 */
#endif /* COMMON_WIN32_DEFS_H */
diff --git a/lib/utils.c b/lib/utils.c
index 8bb4413..036dd60 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -9,8 +9,6 @@
* https://opensource.org/licenses/MIT.
*/
-#define _GNU_SOURCE /* for asprintf() and strerror_r() */
-
#include "lib_private.h"
#include <stdio.h>
@@ -22,7 +20,7 @@ static void *xmalloc(size_t size)
void *p = malloc(size);
if (!p)
- libfsverity_error_msg("out of memory (tried to allocate %" SIZET_PF " bytes)",
+ libfsverity_error_msg("out of memory (tried to allocate %zu bytes)",
size);
return p;
}
- Eric
next prev parent reply other threads:[~2020-12-17 19:20 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-17 14:47 [fsverity-utils PATCH v2 1/2] Remove unneeded includes luca.boccassi
2020-12-17 14:47 ` [fsverity-utils PATCH v2 2/2] Allow to build and run sign/digest on Windows luca.boccassi
2020-12-17 18:32 ` Eric Biggers
2020-12-17 18:44 ` Luca Boccassi
2020-12-17 19:05 ` Eric Biggers
2020-12-17 19:12 ` Luca Boccassi
2020-12-17 19:20 ` Eric Biggers [this message]
2020-12-17 19:26 ` Luca Boccassi
2020-12-17 19:16 ` [fsverity-utils PATCH v3 1/2] Remove unneeded includes luca.boccassi
2020-12-17 19:16 ` [fsverity-utils PATCH v3 2/2] Allow to build and run sign/digest on Windows luca.boccassi
2020-12-17 19:25 ` [fsverity-utils PATCH v4 1/2] Remove unneeded includes luca.boccassi
2020-12-17 19:25 ` [fsverity-utils PATCH v4 2/2] Allow to build and run sign/digest on Windows luca.boccassi
2020-12-21 21:40 ` Eric Biggers
2020-12-21 22:23 ` Luca Boccassi
2020-12-21 22:19 ` [PATCH v5] " Luca Boccassi
2020-12-21 23:03 ` Eric Biggers
2020-12-21 23:26 ` Luca Boccassi
2020-12-21 23:24 ` [PATCH v6 1/3] Move -D_GNU_SOURCE to CPPFLAGS Luca Boccassi
2020-12-21 23:24 ` [PATCH v6 2/3] Wrap ./fsverity in TEST_WRAPPER_PROG too Luca Boccassi
2020-12-21 23:24 ` [PATCH v6 3/3] Allow to build and run sign/digest on Windows Luca Boccassi
2020-12-21 23:53 ` Eric Biggers
2020-12-21 23:57 ` Luca Boccassi
2020-12-22 0:03 ` Eric Biggers
2020-12-22 0:11 ` Luca Boccassi
2020-12-22 0:00 ` [PATCH v6 1/3] Move -D_GNU_SOURCE to CPPFLAGS Eric Biggers
2020-12-22 0:12 ` Luca Boccassi
2020-12-22 0:10 ` [PATCH v7 " Luca Boccassi
2020-12-22 0:10 ` [PATCH v7 2/3] Wrap ./fsverity in TEST_WRAPPER_PROG too Luca Boccassi
2020-12-22 18:41 ` Eric Biggers
2020-12-22 0:10 ` [PATCH v7 3/3] Allow to build and run sign/digest on Windows Luca Boccassi
2020-12-22 18:40 ` Eric Biggers
2020-12-22 8:21 ` [PATCH v7 1/3] Move -D_GNU_SOURCE to CPPFLAGS Eric Biggers
2020-12-22 18:40 ` Eric Biggers
2020-12-21 21:32 ` [fsverity-utils PATCH v4 1/2] Remove unneeded includes Eric Biggers
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=X9uvac1VKpuvZ68B@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=luca.boccassi@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).