gbranden pushed a commit to branch master
in repository groff.

commit 1740c22b4a97b473b25ea68f70ee5fab341bfda6
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Fri Jul 11 07:07:49 2025 -0500

    [preconv]: Fix code style nits (5/6).
    
    * src/preproc/preconv/preconv.cpp (conversion_iconv, do_file): Favor C++
      `static_cast<>` and `const_cast<>` operators over omnipotent C-style
      casts.
    
    Some pretty hairy C-style casts while looping over the input and output
    buffers (to resize them if necessary) remain.  Migrating those will
    demand more careful thought.
---
 ChangeLog                       |  2 ++
 src/preproc/preconv/preconv.cpp | 12 ++++++------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 291ac81a1..7944d51e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,8 @@
        (emacs2mime, check_coding_tag, detect_file_encoding, do_file)
        (main): Explicitly compare values of pointer type to null
        pointer literals instead of letting them pun down to Booleans.
+       (conversion_iconv, do_file): Favor C++ `static_cast<>` and
+       `const_cast<>` operators over omnipotent C-style casts.
 
 2025-07-11  G. Branden Robinson <g.branden.robin...@gmail.com>
 
diff --git a/src/preproc/preconv/preconv.cpp b/src/preproc/preconv/preconv.cpp
index 5be085e17..c43690db5 100644
--- a/src/preproc/preconv/preconv.cpp
+++ b/src/preproc/preconv/preconv.cpp
@@ -701,8 +701,8 @@ conversion_iconv(FILE *fp, const string &data, char *enc)
   char *limit;
   while (inbytes_left > 0) {
     size_t status = iconv(handle,
-                         (ICONV_CONST char **)&inptr, &inbytes_left,
-                         &outptr, &outbytes_left);
+                         static_cast<ICONV_CONST char **>(&inptr),
+                         &inbytes_left, &outptr, &outbytes_left);
     if (status == static_cast<size_t>(-1)) {
       if (EILSEQ == errno) {
        // Invalid byte sequence.  XXX
@@ -735,8 +735,8 @@ conversion_iconv(FILE *fp, const string &data, char *enc)
     inbytes_left += read_bytes;
     while (inbytes_left > 0) {
       size_t status = iconv(handle,
-                           (ICONV_CONST char **)&inptr, &inbytes_left,
-                           &outptr, &outbytes_left);
+                           static_cast<ICONV_CONST char **>(&inptr),
+                           &inbytes_left, &outptr, &outbytes_left);
       if (status == (size_t)-1) {
        if (EILSEQ == errno) {
          // Invalid byte sequence.  XXX
@@ -1154,12 +1154,12 @@ do_file(const char *filename)
        fprintf(stderr, "  but BOM in data stream implies encoding"
                " '%s'!\n", BOM_encoding);
     }
-    encoding = (char *)user_encoding;
+    encoding = static_cast<char *>(user_encoding);
   }
   else if (BOM_encoding != 0 /* nullptr */) {
     if (is_debugging)
       fprintf(stderr, "  found BOM, no search for coding tag\n");
-    encoding = (char *)BOM_encoding;
+    encoding = const_cast<char *>(BOM_encoding);
   }
   else {
     // 'check_coding_tag' returns a pointer to a static array (or a null

_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to