Skip to contentSkip to conversation

libselinux: selinux_restorecon: fix printf format string specifier for uint64_t

PATCH In review Nicolas Iooss 2 participants 3 messages Nov 5, 2018 – Nov 11, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: selinux_restorecon: fix printf format string specifier for uint64_t

fc_count is defined as uint64_t, which needs to be printed with PRIu64 (it is "llu" on x86 and "lu" on x86-64). Otherwise, building with 'CC="gcc -m32"' fails with:

selinux_restorecon.c: In function ‘restorecon_sb’:
selinux_restorecon.c:633:26: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
fprintf(stdout, "\r%luk", fc_count / STAR_COUNT);
~~^
%llu

---
 libselinux/src/selinux_restorecon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/src/selinux_restorecon.c +2 -1
index 41f2225081e0..3df2d382d50b 100644
@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <fts.h>
+#include <inttypes.h>
 #include <limits.h>
 #include <stdint.h>
 #include <sys/types.h>
@@ -630,7 +631,7 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
 					     fc_count / efile_count) : 100;
 				fprintf(stdout, "\r%-.1f%%", (double)pc);
 			} else {
-				fprintf(stdout, "\r%luk", fc_count / STAR_COUNT);
+				fprintf(stdout, "\r%" PRIu64 "k", fc_count / STAR_COUNT);
 			}
 			fflush(stdout);
 		}
Signature · 1 line
2.19.1
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Nicolas Iooss

fc_count is defined as uint64_t, which needs to be printed with PRIu64 (it is "llu" on x86 and "lu" on x86-64). Otherwise, building with 'CC="gcc -m32"' fails with:

selinux_restorecon.c: In function ‘restorecon_sb’:
selinux_restorecon.c:633:26: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
fprintf(stdout, "\r%luk", fc_count / STAR_COUNT);
~~^
%llu

Quoted 1 line
Quoted 26 lines
---
  libselinux/src/selinux_restorecon.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/src/selinux_restorecon.c +2 -1
index 41f2225081e0..3df2d382d50b 100644
@@ -15,6 +15,7 @@
  #include <errno.h>
  #include <fcntl.h>
  #include <fts.h>
+#include <inttypes.h>
  #include <limits.h>
  #include <stdint.h>
  #include <sys/types.h>
@@ -630,7 +631,7 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
  					     fc_count / efile_count) : 100;
  				fprintf(stdout, "\r%-.1f%%", (double)pc);
  			} else {
-				fprintf(stdout, "\r%luk", fc_count / STAR_COUNT);
+				fprintf(stdout, "\r%" PRIu64 "k", fc_count / STAR_COUNT);
  			}
  			fflush(stdout);
  		}
#2 lore raw
Quoted 14 lines · Stephen Smalley
Quoted 12 lines · Nicolas Iooss

fc_count is defined as uint64_t, which needs to be printed with PRIu64 (it is "llu" on x86 and "lu" on x86-64). Otherwise, building with 'CC="gcc -m32"' fails with:

selinux_restorecon.c: In function ‘restorecon_sb’:
selinux_restorecon.c:633:26: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
fprintf(stdout, "\r%luk", fc_count / STAR_COUNT);
~~^
%llu

Quoted 3 lines
Quoted 1 line

Merged.

Nicolas