Change a number of sprintf to snprintf.

Fixes a number of -Werrors about format overflow from GCC 8.
This commit is contained in:
Augustin Cavalier
2019-05-24 14:23:56 -04:00
parent 5b189b0e1e
commit a1ad8af64e
6 changed files with 19 additions and 13 deletions
+7 -5
View File
@@ -1845,8 +1845,10 @@ TTextView::Open(hyper_text *enclosure)
char baseName[B_FILE_NAME_LENGTH];
strcpy(baseName, enclosure->name ? enclosure->name : "enclosure");
strcpy(name, baseName);
for (int32 index = 0; dir.Contains(name); index++)
sprintf(name, "%s_%" B_PRId32, baseName, index);
for (int32 index = 0; dir.Contains(name); index++) {
snprintf(name, B_FILE_NAME_LENGTH, "%s_%" B_PRId32,
baseName, index);
}
BEntry entry(path.Path());
entry_ref ref;
@@ -2234,7 +2236,7 @@ TTextView::Reader::ParseMail(BMailContainer *container,
if (enclosure == NULL)
return false;
memset(enclosure, 0, sizeof(hyper_text));
memset((void*)enclosure, 0, sizeof(hyper_text));
enclosure->type = TYPE_ENCLOSURE;
@@ -2264,7 +2266,7 @@ TTextView::Reader::ParseMail(BMailContainer *container,
if (enclosure == NULL)
return false;
memset(enclosure, 0, sizeof(hyper_text));
memset((void*)enclosure, 0, sizeof(hyper_text));
enclosure->type = TYPE_ENCLOSURE;
enclosure->component = component;
@@ -2344,7 +2346,7 @@ TTextView::Reader::Process(const char *data, int32 data_len, bool isHeader)
if (enclosure == NULL)
return false;
memset(enclosure, 0, sizeof(hyper_text));
memset((void*)enclosure, 0, sizeof(hyper_text));
fView->GetSelection(&enclosure->text_start,
&enclosure->text_end);
enclosure->type = type;
+2 -1
View File
@@ -165,7 +165,8 @@ TStatusWindow::MessageReceived(BMessage* msg)
break;
if (result != EEXIST)
goto err_exit;
sprintf(newName, "%s_%" B_PRId32, name, index++);
snprintf(newName, B_FILE_NAME_LENGTH, "%s_%" B_PRId32,
name, index++);
}
dir.FindEntry(newName, &entry);
node = new BNodeInfo(&file);
+4 -3
View File
@@ -1311,9 +1311,10 @@ TermParse::_DeviceStatusReport(int n)
}
case 6:
// Cursor position report requested
len = sprintf(sbuf, "\033[%" B_PRId32 ";%" B_PRId32 "R",
fBuffer->Cursor().y + 1,
fBuffer->Cursor().x + 1);
len = snprintf(sbuf, sizeof(sbuf),
"\033[%" B_PRId32 ";%" B_PRId32 "R",
fBuffer->Cursor().y + 1,
fBuffer->Cursor().x + 1);
write(fFd, sbuf, len);
break ;
default:
+2 -1
View File
@@ -376,7 +376,8 @@ AssociatedTypes::BuildAssociatedTypesTable()
BPrivate::Storage::to_lower(subtype);
char fulltype[B_PATH_NAME_LENGTH];
sprintf(fulltype, "%s/%s", supertype, subtype);
snprintf(fulltype, B_PATH_NAME_LENGTH, "%s/%s",
supertype, subtype);
// Process the subtype
ProcessType(fulltype);
+2 -1
View File
@@ -374,7 +374,8 @@ SnifferRules::BuildRuleList()
BPrivate::Storage::to_lower(subtype);
char fulltype[B_PATH_NAME_LENGTH];
sprintf(fulltype, "%s/%s", supertype, subtype);
snprintf(fulltype, B_PATH_NAME_LENGTH, "%s/%s",
supertype, subtype);
// Process the subtype
ProcessType(fulltype, &bytesNeeded);
+2 -2
View File
@@ -2424,7 +2424,7 @@ FSMakeOriginalName(char* name, BDirectory* destDir, const char* suffix)
fnum = 1;
strcpy(temp_name, name);
while (destDir->Contains(temp_name)) {
sprintf(temp_name, "%s %" B_PRId32, copybase, ++fnum);
snprintf(temp_name, sizeof(temp_name), "%s %" B_PRId32, copybase, ++fnum);
if (strlen(temp_name) > (B_FILE_NAME_LENGTH - 1)) {
// The name has grown too long. Maybe we just went from
@@ -2433,7 +2433,7 @@ FSMakeOriginalName(char* name, BDirectory* destDir, const char* suffix)
// truncate the 'root' name and continue.
// ??? should we reset fnum or not ???
root[strlen(root) - 1] = '\0';
sprintf(temp_name, "%s%s %" B_PRId32, root, suffix, fnum);
snprintf(temp_name, sizeof(temp_name), "%s%s %" B_PRId32, root, suffix, fnum);
}
}