From a1ad8af64e5af891b4144d0d971d4e1659751396 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 24 May 2019 14:23:56 -0400 Subject: [PATCH] Change a number of sprintf to snprintf. Fixes a number of -Werrors about format overflow from GCC 8. --- src/apps/mail/Content.cpp | 12 +++++++----- src/apps/mail/Status.cpp | 3 ++- src/apps/terminal/TermParse.cpp | 7 ++++--- src/kits/storage/mime/AssociatedTypes.cpp | 3 ++- src/kits/storage/mime/SnifferRules.cpp | 3 ++- src/kits/tracker/FSUtils.cpp | 4 ++-- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/apps/mail/Content.cpp b/src/apps/mail/Content.cpp index 716d97c282..e174f74185 100644 --- a/src/apps/mail/Content.cpp +++ b/src/apps/mail/Content.cpp @@ -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; diff --git a/src/apps/mail/Status.cpp b/src/apps/mail/Status.cpp index 6911efddcc..dce4065c3e 100644 --- a/src/apps/mail/Status.cpp +++ b/src/apps/mail/Status.cpp @@ -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); diff --git a/src/apps/terminal/TermParse.cpp b/src/apps/terminal/TermParse.cpp index b80d3d997a..b8ac127e14 100644 --- a/src/apps/terminal/TermParse.cpp +++ b/src/apps/terminal/TermParse.cpp @@ -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: diff --git a/src/kits/storage/mime/AssociatedTypes.cpp b/src/kits/storage/mime/AssociatedTypes.cpp index a8d966d0e7..109007752a 100644 --- a/src/kits/storage/mime/AssociatedTypes.cpp +++ b/src/kits/storage/mime/AssociatedTypes.cpp @@ -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); diff --git a/src/kits/storage/mime/SnifferRules.cpp b/src/kits/storage/mime/SnifferRules.cpp index 0efdb936e1..f9211fb674 100644 --- a/src/kits/storage/mime/SnifferRules.cpp +++ b/src/kits/storage/mime/SnifferRules.cpp @@ -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); diff --git a/src/kits/tracker/FSUtils.cpp b/src/kits/tracker/FSUtils.cpp index 19dbe280d9..2603d62b50 100644 --- a/src/kits/tracker/FSUtils.cpp +++ b/src/kits/tracker/FSUtils.cpp @@ -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); } }