On Mon, 19 Nov 2018 13:31:25 -0500
George Koehler <kern...@gmail.com> wrote:

> My powerpc machine is using the gcc 6 diff from
> https://marc.info/?l=openbsd-ports&m=154165621429861&w=2
> 
> This is using gcc-6.4.0p2 as ports-gcc, and has now failed to build
> devel/cmake.... (It fails) because gcc 6 warns when linking any
> C++ program:
> 
> $ eg++ -o simple simple.cc 
> /usr/local/lib/gcc/powerpc-unknown-openbsd6.4/6.4.0/../../../libestdc++.so.18.0:
>  warning: sprintf() is often misused, please use snprintf()

I now propose a patch for lang/gcc/6 that silences the above warning.
With this patch, lang/gcc/6 builds devel/cmake successfully.  The
patch removes sprintf() from libestdc++.so but doesn't touch other
sprintf() calls in /usr/local/include/c++/6.4.0/ext/throw_allocator.h;
I did use base-gcc's /usr/include/g++/ext/throw_allocator.h as an
example of snprintf().

I only did `make update-patches` and `make rebuild`.  I didn't try
`make clean patch` because a new build would take about 24 hours.
I also don't know if my snprintf()s are correct, because my C++
executables might not be calling that code in libestdc++.

Patch is for lang/gcc/6, doesn't include REVISION bump.

Index: patches/patch-libstdc++-v3_src_c++11_debug_cc
===================================================================
RCS file: patches/patch-libstdc++-v3_src_c++11_debug_cc
diff -N patches/patch-libstdc++-v3_src_c++11_debug_cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-libstdc++-v3_src_c++11_debug_cc       20 Nov 2018 00:49:23 
-0000
@@ -0,0 +1,65 @@
+$OpenBSD$
+
+Silence this linker warning:
+/usr/local/lib/gcc/powerpc-unknown-openbsd6.4/6.4.0/../../../libestdc++.so.18.0:
+ warning: sprintf() is often misused, please use snprintf()
+
+Index: libstdc++-v3/src/c++11/debug.cc
+--- libstdc++-v3/src/c++11/debug.cc.orig
++++ libstdc++-v3/src/c++11/debug.cc
+@@ -660,7 +660,7 @@ namespace
+     else if (__builtin_strcmp(name, "address") == 0)
+       {
+       char buf[64];
+-      int ret = __builtin_sprintf(buf, "%p", inst._M_address);
++      int ret = snprintf(buf, sizeof buf, "%p", inst._M_address);
+       print_word(ctx, buf, ret);
+       }
+     else
+@@ -712,7 +712,7 @@ namespace
+       else if (__builtin_strcmp(name, "sequence") == 0)
+         {
+           assert(iterator._M_sequence);
+-          int written = __builtin_sprintf(buf, "%p", iterator._M_sequence);
++          int written = snprintf(buf, sizeof buf, "%p", iterator._M_sequence);
+           print_word(ctx, buf, written);
+         }
+       else if (__builtin_strcmp(name, "seq_type") == 0)
+@@ -797,7 +797,7 @@ namespace
+       }
+ 
+     int written
+-      = __builtin_sprintf(buf, "@ 0x%p {\n", inst._M_address);
++      = snprintf(buf, sizeof buf, "@ 0x%p {\n", inst._M_address);
+     print_word(ctx, buf, written);
+ 
+     if (inst._M_type)
+@@ -853,7 +853,7 @@ namespace
+               }
+ 
+             int written
+-              = __builtin_sprintf(buf, "@ 0x%p\n", ite._M_sequence);
++              = snprintf(buf, sizeof buf, "@ 0x%p\n", ite._M_sequence);
+             print_word(ctx, buf, written);
+           }
+ 
+@@ -951,8 +951,8 @@ namespace
+           if (param._M_kind == _Parameter::__integer)
+             {
+               int written
+-                = __builtin_sprintf(buf, "%ld",
+-                                    param._M_variant._M_integer._M_value);
++                = snprintf(buf, sizeof buf, "%ld",
++                           param._M_variant._M_integer._M_value);
+               print_word(ctx, buf, written);
+             }
+           else if (param._M_kind == _Parameter::__string)
+@@ -1012,7 +1012,7 @@ namespace __gnu_debug
+     if (_M_line > 0)
+       {
+       char buf[64];
+-      int written = __builtin_sprintf(buf, "%u:", _M_line);
++      int written = snprintf(buf, sizeof buf, "%u:", _M_line);
+       print_word(ctx, buf, written);
+       go_to_next_line = true;
+       }

-- 
George Koehler <kern...@gmail.com>

Reply via email to