Ticket #3651: 3651-Enh2-2.patch

File 3651-Enh2-2.patch, 2.5 KB (added by dsizzle, 9 years ago)

rewrote C-style string operations for displayName to use BString - apply *after* 3651-Enh2.patch

  • src/apps/charactermap/CharacterWindow.cpp

    From b222c363913badd2fc4d0dcf24a5cfa2f5e2a12e Mon Sep 17 00:00:00 2001
    From: dsizzle <dcieslak@yahoo.com>
    Date: Mon, 24 Nov 2014 21:20:37 +0000
    Subject: [PATCH] 3651: Enhancement 2 - rewrote C-style string code to use
     BString
    
    ---
     src/apps/charactermap/CharacterWindow.cpp | 24 +++++-------------------
     1 file changed, 5 insertions(+), 19 deletions(-)
    
    diff --git a/src/apps/charactermap/CharacterWindow.cpp b/src/apps/charactermap/CharacterWindow.cpp
    index d159c0e..ff6d1cb 100644
    a b CharacterWindow::CharacterWindow()  
    177177   
    178178    const char* family;
    179179    const char* style;
    180     char* displayName;
     180    BString displayName;
    181181   
    182182    if (settings.FindString("font family", &family) == B_OK
    183183        && settings.FindString("font style", &style) == B_OK) {
    184184        _SetFont(family, style);
    185         displayName = new char[strlen(family) + strlen(style) + 4];
    186         strcpy(displayName, family);
    187         strcat(displayName, " > ");
    188         strcat(displayName, style);
     185        displayName << family << " " << style;
    189186    } else {
    190187        font_family currentFontFamily;
    191188        font_style currentFontStyle;
    192189        fCharacterView->CharacterFont().GetFamilyAndStyle(&currentFontFamily,
    193190            &currentFontStyle);
    194         displayName = new char[strlen(currentFontFamily)
    195             + strlen(currentFontStyle) + 4];
    196         strcpy(displayName, currentFontFamily);
    197         strcat(displayName, " > ");
    198         strcat(displayName, currentFontStyle);
     191        displayName << currentFontFamily << " " << currentFontStyle;
    199192    }
    200193
    201194    int32 fontSize;
    CharacterWindow::CharacterWindow()  
    219212        new BMessage(kMsgFontSizeChanged), kMinFontSize, kMaxFontSize);
    220213    fFontSizeSlider->SetValue(fontSize);
    221214    fFontSizeSlider->SetLabel(displayName);
    222     delete(displayName);
    223215   
    224216    fCodeView = new BStringView("code", "-");
    225217    fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
    CharacterWindow::MessageReceived(BMessage* message)  
    407399
    408400                _SetFont(item->Menu()->Name(), item->Label());
    409401               
    410                 char* displayName;
    411                 displayName = new char[strlen(item->Menu()->Name())
    412                     +strlen(item->Label()) + 4];
    413                 strcpy(displayName, item->Menu()->Name());
    414                 strcat(displayName, " > ");
    415                 strcat(displayName, item->Label());
     402                BString displayName;
     403                displayName << item->Menu()->Name() << " " << item->Label();
    416404           
    417405                fFontSizeSlider->SetLabel(displayName);
    418406               
    419                 delete(displayName);
    420                
    421407                item = item->Menu()->Superitem();
    422408                item->SetMarked(true);
    423409            }