Skip to content

Commit

Permalink
Use 'messageBox' directly without 'ostrstream'
Browse files Browse the repository at this point in the history
This is simpler and less prone to memory safety errors.
  • Loading branch information
magiblot committed May 21, 2024
1 parent 545bc7d commit 93f494c
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 55 deletions.
6 changes: 1 addition & 5 deletions examples/tvdemo/fileview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ __link(RScrollBar)
#include <stdlib.h>
#include <ctype.h>

#include <strstrea.h>
#include <fstream.h>

#include "tvcmds.h"
Expand Down Expand Up @@ -93,10 +92,7 @@ void TFileViewer::readFile( const char *fName )
ifstream fileToView( fName );
if( !fileToView )
{
char buf[256] = {0};
ostrstream os( buf, sizeof( buf )-1 );
os << "Failed to open file '" << fName << "'." << ends;
messageBox( buf, mfError | mfOKButton );
messageBox( mfError | mfOKButton, "Failed to open file '%s'.", fName );
isValid = False;
}
else
Expand Down
10 changes: 1 addition & 9 deletions examples/tvforms/fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ __link( RInputLine )
#include <stdlib.h>
#endif // __STDLIB_H

#if !defined( __STRSTREAM_H )
#include <strstrea.h>
#endif // __STRSTREAM_H


// TKeyInputLine

const char *const TKeyInputLine::name = "TKeyInputLine";
Expand Down Expand Up @@ -137,8 +132,6 @@ Boolean TNumInputLine::valid( ushort command )
{
int32_t value;
Boolean ok;
char msg[80];
ostrstream os(msg, 80);

ok = True;
if ( (command != cmCancel) && (command != cmValid) )
Expand All @@ -149,8 +142,7 @@ Boolean TNumInputLine::valid( ushort command )
if ( (value == 0) || (value < min) || (value > max) )
{
select();
os << "Number must be from " << min << " to " << max << "." << ends;
messageBox(os.str(), mfError + mfOKButton);
messageBox(mfError | mfOKButton, "Number must be from %ld to %ld.", (long) min, (long) max);
selectAll(True);
ok = False;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tvforms/genparts.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ TForm *makeForm()
y = 2;

r = TRect(inputCol, y, inputCol + partNumWidth + 2, y + 1);
c = new TNumInputLine(r, partNumWidth, 0, 9999);
c = new TNumInputLine(r, partNumWidth, 1, 9999);
f->insert(c);

r = TRect(labelCol, y, labelCol + labelWid, y + 1);
Expand Down
10 changes: 1 addition & 9 deletions source/tvision/tchdrdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
#include <string.h>
#endif // __STRING_H

#if !defined( __STRSTREAM_H )
#include <strstrea.h>
#endif

TChDirDialog::TChDirDialog( ushort opts, ushort histId ) noexcept :
TWindowInit( &TChDirDialog::initFrame ),
TDialog( TRect( 16, 2, 64, 20 ), changeDirTitle )
Expand Down Expand Up @@ -215,11 +211,7 @@ Boolean TChDirDialog::valid( ushort command )

if( changeDir( path ) != 0 )
{
char buf[256];
ostrstream os( buf, sizeof( buf )-1 );
os << invalidText << ": '" << path << "'." << ends;
buf[sizeof( buf )-1] = '\0';
messageBox( buf, mfError | mfOKButton );
messageBox( mfError | mfOKButton, "%s: '%s'.", invalidText, path );
return False;
}
return True;
Expand Down
18 changes: 1 addition & 17 deletions source/tvision/tdirlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,14 @@ TDirListBox::~TDirListBox()

void TDirListBox::getText( char *text, short item, short maxChars )
{
strncpy( text, list()->at(item)->text(), maxChars );
text[maxChars] = '\0';
strnzcpy( text, list()->at(item)->text(), maxChars + 1 );
}

void TDirListBox::selectItem( short item )
{
message( owner, evCommand, cmChangeDir, list()->at(item) );
}

/*
void TDirListBox::handleEvent( TEvent& event )
{
if( event.what == evMouseDown && (event.mouse.eventFlags & meDoubleClick) )
{
event.what = evCommand;
event.message.command = cmChangeDir;
putEvent( event );
clearEvent( event );
}
else
TListBox::handleEvent( event );
}
*/

Boolean TDirListBox::isSelected( short item )
{
return Boolean( item == cur );
Expand Down
16 changes: 2 additions & 14 deletions source/tvision/tfildlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
#include <string.h>
#endif // __STRING_H

#if !defined( __STRSTREAM_H )
#include <strstrea.h>
#endif

TFileDialog::TFileDialog( TStringView aWildCard,
TStringView aTitle,
TStringView inputName,
Expand Down Expand Up @@ -288,11 +284,7 @@ Boolean TFileDialog::checkDirectory( const char *str )
return True;
else
{
char buf[256];
ostrstream os( buf, sizeof( buf )-1 );
os << invalidDriveText << ": '" << str << "'" << ends;
buf[sizeof( buf )-1] = '\0';
messageBox( buf, mfError | mfOKButton );
messageBox( mfError | mfOKButton, "%s: '%s'", invalidDriveText, str );
fileName->select();
return False;
}
Expand Down Expand Up @@ -348,11 +340,7 @@ char ext[MAXEXT];
return True;
else
{
char buf[256];
ostrstream os( buf, sizeof( buf )-1 );
os << invalidFileText << ": '" << fName << "'" << ends;
buf[sizeof( buf )-1] = '\0';
messageBox( buf, mfError | mfOKButton );
messageBox( mfError | mfOKButton, "%s: '%s'", invalidFileText, fName );
return False;
}
}
Expand Down

0 comments on commit 93f494c

Please sign in to comment.