Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

fix undefined usage of posix `basename()` passing `const char *`

Aperta
#4,019 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@GitMensch ci sta già lavorando.

Dal 16/9/2025.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

per Linux Manpage:

There are two different versions of basename() - the POSIX version described above, and the GNU version, which one gets after

   #define _GNU_SOURCE         /* See feature_test_macros */
   #include <string.h>

The GNU version never modifies its argument, and returns the empty string when path has a trailing slash, and in particular also when it is "/". There is no GNU version of dirname().

With glibc, one gets the POSIX version of basename() when <libgen.h> is included, and the GNU version otherwise.

The inclusion of <string.h> to use basename() also breaks building outside of glibc, as seen in #4009's build log in TraceStream.cc.
If we keep using it, then we should explicit use the posix version by #include <libgen.h> in both current uses (only C++, in C we use a hard `strrchr(exe_image, '/').

So... What should it be (I'll do the PR):

  • use posix version with a temporary copy of the c_str/data to a buffer and including the header
  • use a C++ version with
    • a hard path.substr with path.find_last_of('/') + 1 in both places
    • a wrapper function base_name which allows also files without a path [not checking for nullptr as that is up to the caller], either defined in both files or a util header
  • something else (note: using fs::path(exe_path).filename().string() won't work as the Wiki mentions RHEL7 and Ubuntu 14 - both don't have a compiler new enough installed per default; side note: I did not found an explicit minimal compiler version in the Wiki, but guess there must be one and the ancient GCC4.8/clang 3.4 distributed by those systems' package managers are possibly not working)
Lingua principale
C++
Stelle
10.7k
Fork
665
Merge medio
2g 7h
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rr-debugger/rr

Tutte le issue di rr-debugger/rr

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.