layer23: Fix gcc warning sprintf() writing on too short buf

Triggered with gcc 12.2.0:
/osmocom-bb/src/host/layer23/src/common/sysinfo.c: In function ‘gsm48_sysinfo_dump’:
/osmocom-bb/src/host/layer23/src/common/sysinfo.c:198:42: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
  198 |                 sprintf(buffer + 69, " %d", i + 63);
      |                                          ^
/osmocom-bb/src/host/layer23/src/common/sysinfo.c:198:17: note: ‘sprintf’ output between 3 and 13 bytes into a destination of size 12
  198 |                 sprintf(buffer + 69, " %d", i + 63);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I29a64fbb7aca0d1b469b6d278d4a24ddc6f57b3a
This commit is contained in:
Pau Espin 2023-01-12 12:11:16 +01:00 committed by pespin
parent 49d993e4ab
commit 7c3eb69c67
1 changed files with 3 additions and 3 deletions

View File

@ -68,7 +68,7 @@ int gsm48_sysinfo_dump(const struct gsm48_sysinfo *s, uint16_t arfcn,
void (*print)(void *, const char *, ...),
void *priv, uint8_t *freq_map)
{
char buffer[81];
char buffer[82];
int i, j, k, index;
int refer_pcs = gsm_refer_pcs(arfcn, s);
@ -173,7 +173,7 @@ int gsm48_sysinfo_dump(const struct gsm48_sysinfo *s, uint16_t arfcn,
/* frequency map */
for (i = 0; i < 1024; i += 64) {
sprintf(buffer, " %3d ", i);
snprintf(buffer, sizeof(buffer), " %3d ", i);
for (j = 0; j < 64; j++) {
index = i+j;
if (refer_pcs && index >= 512 && index <= 885)
@ -195,7 +195,7 @@ int gsm48_sysinfo_dump(const struct gsm48_sysinfo *s, uint16_t arfcn,
}
for (; j < 64; j++)
buffer[j + 5] = ' ';
sprintf(buffer + 69, " %d", i + 63);
snprintf(buffer + 69, sizeof(buffer) - 69, " %d", i + 63);
print(priv, "%s\n", buffer);
}
print(priv, " 'S' = serv. cell 'n' = SI2 (neigh.) 'r' = SI5 (rep.) "