groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 17/35: src/libs/libgroff/string.cpp: Fix Solaris 10 wart.


From: G. Branden Robinson
Subject: [groff] 17/35: src/libs/libgroff/string.cpp: Fix Solaris 10 wart.
Date: Tue, 10 Dec 2024 16:35:34 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 0d0dd80a786da13d33d19757441638efd36a427d
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Dec 8 01:55:46 2024 -0600

    src/libs/libgroff/string.cpp: Fix Solaris 10 wart.
    
    * src/libs/libgroff/libgroff.am (libgroff_a_LIBADD): Add to ensure
      linkage with gnulib.
    
    * src/libs/libgroff/string.cpp: Align with modern groff conventions.
      Include "<stdio.h>" header file to ensure visibility of `FILE`,
      `putc()` and `sprintf()` symbols.  Include "<string.h>" header file to
      ensure visibility of `memmem()` declaration; problem detected on
      Solaris 10.  Parenthesize complex expressions.
    
      (string::extract): Use C++ `static_cast` operator instead of C-style
      type cast.
    
    Futher annotate system #includes.  Use whitespace around binary
    operators.  Break long lines.
---
 ChangeLog                     | 13 +++++++++++++
 src/libs/libgroff/libgroff.am |  2 ++
 src/libs/libgroff/string.cpp  | 21 +++++++++++++--------
 3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9842e60e2..795b30eae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-12-08  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/libs/libgroff/libgroff.am (libgroff_a_LIBADD): Add to
+       ensure linkage with gnulib.
+       * src/libs/libgroff/string.cpp: Align with modern groff
+       conventions.  Include "<stdio.h>" header file to ensure
+       visibility of `FILE`, `putc()` and `sprintf()` symbols.  Include
+       "<string.h>" header file to ensure visibility of `memmem()`
+       declaration; problem detected on Solaris 10.  Parenthesize
+       complex expressions.
+       (string::extract): Use C++ `static_cast` operator instead of
+       C-style type cast.
+
 2024-12-07  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [troff]: The `open` and `opena` requests now accept leading and
diff --git a/src/libs/libgroff/libgroff.am b/src/libs/libgroff/libgroff.am
index cdb810cf3..b43fec4c6 100644
--- a/src/libs/libgroff/libgroff.am
+++ b/src/libs/libgroff/libgroff.am
@@ -76,6 +76,8 @@ libgroff_a_SOURCES += \
 endif
 nodist_libgroff_a_SOURCES = src/libs/libgroff/version.cpp
 
+libgroff_a_LIBADD = lib/libgnu.a
+
 # TODO: these .c files could be removed (use gnulib instead).
 EXTRA_DIST += \
   src/libs/libgroff/mkstemp.cpp \
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index b48761703..c8d759528 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -20,7 +20,10 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <config.h>
 #endif
 
-#include <stdlib.h>
+#include <stdio.h> // FILE, putc(), sprintf()
+#include <stdlib.h> // malloc()
+#include <string.h> // memchr(), memcmp(), memcpy(), memmem(), memset(),
+                   // strlen(), size_t
 
 #include "lib.h"
 
@@ -29,7 +32,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 static char *salloc(int len, int *sizep);
 static void sfree(char *ptr, int size);
 static char *sfree_alloc(char *ptr, int size, int len, int *sizep);
-static char *srealloc(char *ptr, int size, int oldlen, int newlen, int *sizep);
+static char *srealloc(char *ptr, int size, int oldlen, int newlen,
+                     int *sizep);
 
 static char *salloc(int len, int *sizep)
 {
@@ -38,7 +42,7 @@ static char *salloc(int len, int *sizep)
     return 0;
   }
   else
-    return new char[*sizep = len*2];
+    return new char[*sizep = (len * 2)];
 }
 
 static void sfree(char *ptr, int)
@@ -58,10 +62,11 @@ static char *sfree_alloc(char *ptr, int oldsz, int len, int 
*sizep)
     return 0;
   }
   else
-    return new char[*sizep = len*2];
+    return new char[*sizep = (len * 2)];
 }
 
-static char *srealloc(char *ptr, int oldsz, int oldlen, int newlen, int *sizep)
+static char *srealloc(char *ptr, int oldsz, int oldlen, int newlen,
+                     int *sizep)
 {
   if (oldsz >= newlen) {
     *sizep = oldsz;
@@ -73,7 +78,7 @@ static char *srealloc(char *ptr, int oldsz, int oldlen, int 
newlen, int *sizep)
     return 0;
   }
   else {
-    char *p = new char[*sizep = newlen*2];
+    char *p = new char[*sizep = (newlen * 2)];
     if (oldlen < newlen && oldlen != 0)
       memcpy(p, ptr, oldlen);
     delete[] ptr;
@@ -305,7 +310,7 @@ char *string::extract() const
   for (i = 0; i < n; i++)
     if (p[i] == '\0')
       nnuls++;
-  char *q =(char*)malloc(n + 1 - nnuls);
+  char *q = static_cast<char *>(malloc(n + 1 - nnuls));
   if (q != 0 /* nullptr */) {
     char *r = q;
     for (i = 0; i < n; i++)
@@ -319,7 +324,7 @@ char *string::extract() const
 void string::remove_spaces()
 {
   int l = len - 1;
-  while (l >= 0 && ptr[l] == ' ')
+  while ((l >= 0) && (ptr[l] == ' '))
     l--;
   char *p = ptr;
   if (l > 0)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]