ALT Linux Bugzilla
– Attachment 12996 Details for
Bug 45927
procps: ошибка сборки с GCC 13
New bug
|
Search
|
[?]
|
Help
Register
|
Log In
[x]
|
Forgot Password
Login:
[x]
|
EN
|
RU
[patch]
патч
0001-top-fixed-build-error-with-GCC-13.patch (text/plain), 5.14 KB, created by
Alexey Sheplyakov
on 2023-04-21 15:42:01 MSK
(
hide
)
Description:
патч
Filename:
MIME Type:
Creator:
Alexey Sheplyakov
Created:
2023-04-21 15:42:01 MSK
Size:
5.14 KB
patch
obsolete
>From 24e637b5adf64c7cae2dfe4a7e379710cff562f3 Mon Sep 17 00:00:00 2001 >From: Alexey Sheplyakov <asheplyakov@basealt.ru> >Date: Fri, 21 Apr 2023 16:33:04 +0400 >Subject: [PATCH] top: fixed build error with GCC 13 > >top/top.c: In function 'keys_window': >top/top.c:4471:55: error: '%s' directive output may be truncated writing up to 127 bytes into a region of size 4 [-Werror=format-truncation=] > 4471 | snprintf(q->rc.winname, sizeof(q->rc.winname), "%s", name); > | ^~ >...... > 5631 | if (tmp[0] && tmp[0] != kbd_ESC) win_names(w, tmp); > | ~~~ >In function 'win_names', > inlined from 'keys_window' at top/top.c:5631:46: >top/top.c:4471:7: note: 'snprintf' output between 1 and 128 bytes into a destination of size 4 > 4471 | snprintf(q->rc.winname, sizeof(q->rc.winname), "%s", name); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >top/top.c: In function 'keys_window': >top/top.c:4472:49: error: '%s' directive output may be truncated writing up to 127 bytes into a region of size between 0 and 4 [-Werror=format-truncation=] > 4472 | snprintf(q->grpname, sizeof(q->grpname), "%d:%s", q->winnum, name); > | ^~ >...... > 5631 | if (tmp[0] && tmp[0] != kbd_ESC) win_names(w, tmp); > | ~~~ >In function 'win_names', > inlined from 'keys_window' at top/top.c:5631:46: >top/top.c:4472:4: note: 'snprintf' output between 3 and 140 bytes into a destination of size 6 > 4472 | snprintf(q->grpname, sizeof(q->grpname), "%d:%s", q->winnum, name); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >cc1: all warnings being treated as errors > >5628 if (ALTCHKw) { >5629 char tmp[SMLBUFSIZ]; >5630 STRLCPY(tmp, ioline(fmtmk(N_fmt(NAME_windows_fmt), w->rc.winname))); >5631 if (tmp[0] && tmp[0] != kbd_ESC) win_names(w, tmp); >5632 } >5633 break; > >$ grep -r -n -E 'define\s+SMLBUFSIZ\b' >top/top.h:139:#define SMLBUFSIZ 128 > >4467 static void win_names (WIN_t *q, const char *name) { >4468 /* note: sprintf/snprintf results are "undefined" when src==dst, >4469 according to C99 & POSIX.1-2001 (thanks adc) */ >4470 if (q->rc.winname != name) >4471 snprintf(q->rc.winname, sizeof(q->rc.winname), "%s", name); >4472 snprintf(q->grpname, sizeof(q->grpname), "%d:%s", q->winnum, name); >4473 } // end: win_names > >$ grep -e 'winname' 'top/top.h' > > char winname [WINNAMSIZ], // name for the window, user changeable > >It looks like the above code indeed writes up to 128 bytes into a 4-byte buffer. >To avoid the warning >1) Specify the maximal string length in the format string, like "%.4s". >2) Add one more byte to winname (for a terminating '\0' character). > >ALTBUG: #45927 > >l >--- > top/top.c | 9 +++++++-- > top/top.h | 4 ++-- > 2 files changed, 9 insertions(+), 4 deletions(-) > >diff --git a/top/top.c b/top/top.c >index e64c8660..8636ac20 100644 >--- a/top/top.c >+++ b/top/top.c >@@ -4462,16 +4462,21 @@ static void whack_terminal (void) { > > /*###### Windows/Field Groups support #################################*/ > >+#define xstr(s) str(s) >+#define str(s) #s >+ > /* > * Value a window's name and make the associated group name. */ > static void win_names (WIN_t *q, const char *name) { > /* note: sprintf/snprintf results are "undefined" when src==dst, > according to C99 & POSIX.1-2001 (thanks adc) */ > if (q->rc.winname != name) >- snprintf(q->rc.winname, sizeof(q->rc.winname), "%s", name); >- snprintf(q->grpname, sizeof(q->grpname), "%d:%s", q->winnum, name); >+ snprintf(q->rc.winname, sizeof(q->rc.winname), "%." xstr(WINNAMSIZ) "s", name); >+ snprintf(q->grpname, sizeof(q->grpname), "%d:%." xstr(WINNAMSIZ) "s", q->winnum, name); > } // end: win_names > >+#undef str >+#undef xstr > > /* > * This guy just resets (normalizes) a single window >diff --git a/top/top.h b/top/top.h >index 499d9957..de1e0bf6 100644 >--- a/top/top.h >+++ b/top/top.h >@@ -378,7 +378,7 @@ typedef struct RCW_t { // the 'window' portion of an rcfile > msgsclr, // " in msgs/pmts > headclr, // " in cols head > taskclr; // " in task rows >- char winname [WINNAMSIZ], // name for the window, user changeable >+ char winname [WINNAMSIZ+1], // name for the window, user changeable > fieldscur [PFLAGSSIZ]; // the fields for display & their order > } RCW_t; > >@@ -427,7 +427,7 @@ typedef struct WIN_t { > capclr_rowhigh [CLRBUFSIZ], // are only used when this > capclr_rownorm [CLRBUFSIZ], // window is the 'Curwin'! > cap_bold [CAPBUFSIZ], // support for View_NOBOLD toggle >- grpname [GRPNAMSIZ], // window number:name, printable >+ grpname [GRPNAMSIZ+1], // window number:name, printable > #ifdef USE_X_COLHDR > columnhdr [ROWMINSIZ], // column headings for procflgs > #else >-- >2.33.7 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 45927
:
12996
|
13009