[haiku-commits] haiku: hrev54657 - src/apps/drivesetup

  • From: Adrien Destugues <pulkomandy@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 18 Oct 2020 03:43:51 -0400 (EDT)

hrev54657 adds 1 changeset to branch 'master'
old head: e769acbe8053bdc939992631a09d1095b1467a09
new head: 3d29f848c875100a1c918ecf9c6528cc9cf2b4b9
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=3d29f848c875+%5Ee769acbe8053

----------------------------------------------------------------------------

3d29f848c875: drivesetup: Fix -Wformat-security
  
  Change-Id: Ie5c6d3ea621a1a5704cead8c5e59bf835e907e64
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3322
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

                                      [ Murai Takashi <tmurai01@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev54657
Commit:      3d29f848c875100a1c918ecf9c6528cc9cf2b4b9
URL:         https://git.haiku-os.org/haiku/commit/?id=3d29f848c875
Author:      Murai Takashi <tmurai01@xxxxxxxxx>
Date:        Wed Oct 14 21:29:29 2020 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Sun Oct 18 07:43:45 2020 UTC

----------------------------------------------------------------------------

1 file changed, 27 insertions(+), 27 deletions(-)
src/apps/drivesetup/MainWindow.cpp | 54 +++++++++++++++++-----------------

----------------------------------------------------------------------------

diff --git a/src/apps/drivesetup/MainWindow.cpp 
b/src/apps/drivesetup/MainWindow.cpp
index f1c20bfe0e..e7048a1418 100644
--- a/src/apps/drivesetup/MainWindow.cpp
+++ b/src/apps/drivesetup/MainWindow.cpp
@@ -823,7 +823,7 @@ MainWindow::_DisplayPartitionError(BString _message,
                snprintf(message, sizeof(message), _message.String(), 
name.String());
        } else {
                _message.ReplaceAll("%s", "");
-               snprintf(message, sizeof(message), _message.String());
+               strlcpy(message, _message.String(), sizeof(message));
        }
 
        if (error < B_OK) {
@@ -985,46 +985,44 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id 
selectedPartition,
                }
        }
 
-       char message[512];
-
        if (!found) {
-               snprintf(message, sizeof(message), B_TRANSLATE("Disk system 
\"%s\" "
-                       "not found!"));
-               _DisplayPartitionError(message);
+               _DisplayPartitionError(B_TRANSLATE("Disk system \"%s\" not 
found!"));
                return;
        }
 
+       BString message;
+
        if (diskSystem.IsFileSystem()) {
                BString intelExtendedPartition = "Intel Extended Partition";
                if (disk->ID() == selectedPartition) {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to format a raw disk? (Most people 
initialize the disk "
                                "with a partitioning system first) You will be 
asked "
-                               "again before changes are written to the 
disk."));
+                               "again before changes are written to the 
disk.");
                } else if (partition->ContentName()
                        && strlen(partition->ContentName()) > 0) {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to format the partition \"%s\"? You will 
be asked "
-                               "again before changes are written to the 
disk."),
-                               partition->ContentName());
+                               "again before changes are written to the 
disk.");
+                       message.ReplaceFirst("%s", partition->ContentName());
                } else if (partition->Type() == intelExtendedPartition) {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to format the Intel Extended Partition? 
Any "
                                "subpartitions it contains will be overwritten 
if you "
                                "continue. You will be asked again before 
changes are "
-                               "written to the disk."));
+                               "written to the disk.");
                } else {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to format the partition? You will be 
asked again "
-                               "before changes are written to the disk."));
+                               "before changes are written to the disk.");
                }
        } else {
-               snprintf(message, sizeof(message), B_TRANSLATE("Are you sure 
you "
+               message = B_TRANSLATE("Are you sure you "
                        "want to initialize the selected disk? All data will be 
lost. "
                        "You will be asked again before changes are written to 
the "
-                       "disk.\n"));
+                       "disk.\n");
        }
-       BAlert* alert = new BAlert("first notice", message,
+       BAlert* alert = new BAlert("first notice", message.String(),
                B_TRANSLATE("Continue"), B_TRANSLATE("Cancel"), NULL,
                B_WIDTH_FROM_WIDEST, B_WARNING_ALERT);
        alert->SetShortcut(1, B_ESCAPE);
@@ -1081,30 +1079,32 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id 
selectedPartition,
        // Warn the user one more time...
        if (previousName.Length() > 0) {
                if (partition->IsDevice()) {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to write the changes back to disk 
now?\n\n"
                                "All data on the disk %s will be irretrievably 
lost if you "
-                               "do so!"), previousName.String());
+                               "do so!");
+                       message.ReplaceFirst("%s", previousName.String());
                } else {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to write the changes back to disk 
now?\n\n"
                                "All data on the partition %s will be 
irretrievably lost if you "
-                               "do so!"), previousName.String());
+                               "do so!");
+                       message.ReplaceFirst("%s", previousName.String());
                }
        } else {
                if (partition->IsDevice()) {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to write the changes back to disk 
now?\n\n"
                                "All data on the selected disk will be 
irretrievably lost if "
-                               "you do so!"));
+                               "you do so!");
                } else {
-                       snprintf(message, sizeof(message), B_TRANSLATE("Are you 
sure you "
+                       message = B_TRANSLATE("Are you sure you "
                                "want to write the changes back to disk 
now?\n\n"
                                "All data on the selected partition will be 
irretrievably lost "
-                               "if you do so!"));
+                               "if you do so!");
                }
        }
-       alert = new BAlert("final notice", message,
+       alert = new BAlert("final notice", message.String(),
                B_TRANSLATE("Write changes"), B_TRANSLATE("Cancel"), NULL,
                B_WIDTH_FROM_WIDEST, B_WARNING_ALERT);
        alert->SetShortcut(1, B_ESCAPE);


Other related posts:

  • » [haiku-commits] haiku: hrev54657 - src/apps/drivesetup - Adrien Destugues