genodelabs/genode — Issue #6: Format_string 64bit issue (was mantis id 21)
Author: nfeske
Created: 2011-12-20 08:49:57+00:00
State: open

When using %x in a format string on 64-bit platforms, the resulting string might get malformed when using a number equally or higher than 0xf0000000. Probably due to conversion errors in the format_string classes.

The following patch includes a test case, that triggers the error on 64-bit Genode/linux and Genode/Fiasco.OC. Just run make run/snprintf.

```
diff --git a/os/run/snprintf.run b/os/run/snprintf.run
new file mode 100644
--- /dev/null
+++ b/os/run/snprintf.run
@@ -0,0 +1,38 @@
+build "core init test/snprintf"
+
+create_boot_directory
+
+install_config {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+build_boot_image "core init test-snprintf"
+
+append qemu_args "-m 64"
+
+run_genode_until "child exited with exit value 0" 10
+
+grep_output {^\[init -> test-snprintf}
+
+compare_output_to {
+[init -> test-snprintf] 0xf0000000
+}
\ No newline at end of file
diff --git a/os/src/test/snprintf/main.cc b/os/src/test/snprintf/main.cc
new file mode 100644
--- /dev/null
+++ b/os/src/test/snprintf/main.cc
@@ -0,0 +1,11 @@
+#include
+#include
+
+int main ()
+{
+	using namespace Genode;
+	static char str[1024];
+	snprintf(str, sizeof(str), "0x%x", 0xf0000000);
+	printf("%s\n", str);
+	return 0;
+}
diff --git a/os/src/test/snprintf/target.mk b/os/src/test/snprintf/target.mk
new file mode 100644
--- /dev/null
+++ b/os/src/test/snprintf/target.mk
@@ -0,0 +1,3 @@
+TARGET = test-snprintf
+LIBS = cxx env
+SRC_CC = main.cc

```