[GH-ISSUE #526] Compiler warning assigning to char * from const char * #523

Open
opened 2026-10-02 23:11:49 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @billdenney on GitHub (Aug 7, 2026).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/526

Originally assigned to: @jmcnamara on GitHub.

Related to ropensci/writexl#148

With GCC 16 (default -std=gnu23) and glibc 2.43, the C23 <string.h>
search functions are const-correct: strstr()/strpbrk() on a
const char * return const char *. Four assignments in src/worksheet.c
(current main) then discard the qualifier:

  • _check_table_name(): ptr = strpbrk(name, ...) where name is
    const char * but ptr is char * — ptr is only read, so it can be
    const char *.
  • worksheet_write_url_opt(): found_string = strstr(url, "internal:"),
    "external:", and "mailto:" where url is const char * — the result
    is only null-tested, so if (strstr(url, ...)) avoids the assignment
    (found_string must stay char * for the later writable use on
    url_copy).

CRAN's r-devel Fedora checks treat these as significant warnings, which
affects packages bundling libxlsxwriter (e.g. R's writexl). A patch is applied to writexl's vendored copy in ropensci/writexl#149.

Originally created by @billdenney on GitHub (Aug 7, 2026). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/526 Originally assigned to: @jmcnamara on GitHub. Related to ropensci/writexl#148 With GCC 16 (default `-std=gnu23`) and glibc 2.43, the C23 `<string.h>` search functions are const-correct: `strstr()`/`strpbrk()` on a `const char *` return `const char *`. Four assignments in `src/worksheet.c` (current `main`) then discard the qualifier: * `_check_table_name()`: `ptr = strpbrk(name, ...)` where `name` is `const char *` but `ptr` is `char *` — `ptr` is only read, so it can be `const char *`. * `worksheet_write_url_opt()`: `found_string = strstr(url, "internal:")`, `"external:"`, and `"mailto:"` where `url` is `const char *` — the result is only null-tested, so `if (strstr(url, ...))` avoids the assignment (`found_string` must stay `char *` for the later writable use on `url_copy`). CRAN's r-devel Fedora checks treat these as significant warnings, which affects packages bundling libxlsxwriter (e.g. R's writexl). A patch is applied to writexl's vendored copy in ropensci/writexl#149.
Author
Owner

@jmcnamara commented on GitHub (Aug 7, 2026):

Thanks. I'll look at it.

<!-- gh-comment-id:5218393475 --> @jmcnamara commented on GitHub (Aug 7, 2026): Thanks. I'll look at it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github-starred/libxlsxwriter#523
No description provided.