gbranden pushed a commit to branch master
in repository groff.
commit 39e5565951f235f7555441251d1da9e48b17672b
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Jun 11 05:33:16 2026 -0500
[libgroff]: `string::find()` returns `ssize_t`.
Use a more appropriate return type for `string::find()`: `ssize_t`
instead of `size_t`, since the function can return `-1`.
* src/include/stringclass.h:
* src/libs/libgroff/string.cpp: Preprocessor-include C "<sys/types.h>"
header file to ensure visibility of POSIX.1-2001 type `ssize_t`.
* src/include/stringclass.h: Update function declaration.
* src/libs/libgroff/string.cpp (string::find): Update function
definition.
* src/preproc/tbl/table.cpp: Preprocessor-include C "<sys/types.h>"
header file.
(table::add_entry): Retype `len` local variable from `size_t` to
`ssize_t` to pacify `-Wsign-compare` GCC warning.
---
ChangeLog | 19 +++++++++++++++++++
src/include/stringclass.h | 5 ++++-
src/libs/libgroff/string.cpp | 5 ++++-
src/preproc/tbl/table.cpp | 5 ++++-
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cb8cb46ff..5238e512b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2026-06-11 G. Branden Robinson <[email protected]>
+
+ [libgroff]: Use a more appropriate return type for
+ `string::find()`: `ssize_t` instead of `size_t`, since the
+ function can return `-1`.
+
+ * src/include/stringclass.h:
+ * src/libs/libgroff/string.cpp: Preprocessor-include C
+ "<sys/types.h>" header file to ensure visibility of POSIX.1-2001
+ type `ssize_t`.
+ * src/include/stringclass.h: Update function declaration.
+ * src/libs/libgroff/string.cpp (string::find): Update function
+ definition.
+
+ * src/preproc/tbl/table.cpp: Preprocessor-include C
+ "<sys/types.h>" header file.
+ (table::add_entry): Retype `len` local variable from `size_t` to
+ `ssize_t` to pacify `-Wsign-compare` GCC warning.
+
2026-06-11 G. Branden Robinson <[email protected]>
* src/include/stringclass.h:
diff --git a/src/include/stringclass.h b/src/include/stringclass.h
index 4d9e669fe..c9b47a2f7 100644
--- a/src/include/stringclass.h
+++ b/src/include/stringclass.h
@@ -25,6 +25,9 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <string.h> // memcmp(), strlen()
#include <stdio.h> // FILE
+// POSX/operating system services
+#include <sys/types.h> // ssize_t
+
// Ensure that the first declaration of functions that are later
// declared as inline declares them as inline.
@@ -70,7 +73,7 @@ public:
const char *contents() const;
int search(const char) const;
bool contains(const char) const;
- size_t find(const char *) const;
+ ssize_t find(const char *) const;
char *extract() const;
size_t json_length() const;
const char *json_extract() const;
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index ff2480141..d03d5e2a6 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -28,6 +28,9 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <string.h> // memchr(), memcmp(), memcpy(), memmem(), memset(),
// strlen(), size_t
+// POSX/operating system services
+#include <sys/types.h> // ssize_t
+
#include <new> // std::bad_alloc
#include "cset.h" // csprint()
@@ -339,7 +342,7 @@ bool string::contains(const char c) const
}
// Return index of substring `c` in string, -1 if not found.
-size_t string::find(const char *c) const
+ssize_t string::find(const char *c) const
{
const char *p = ptr
? static_cast<const char *>(memmem(ptr, len, c,
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index 7fbbb26d5..5b75dfcc6 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -23,6 +23,9 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <stdio.h> // fputs(), fwrite(), putchar(), stdout
#include <stdlib.h> // free()
+// POSX/operating system services
+#include <sys/types.h> // ssize_t
+
#include "table.h"
#define BAR_HEIGHT ".25m"
@@ -1538,7 +1541,7 @@ void table::add_entry(int r, int c, const string &str,
{
allocate(r);
table_entry *e = 0 /* nullptr */;
- size_t len = str.length();
+ ssize_t len = str.length();
char *s = str.extract();
// Diagnose escape sequences that can wreak havoc in generated output.
if (len > 1) {
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit