Convert sprintf()s to snprintf()s. Issue #6

This commit is contained in:
Morgan Aldridge 2020-12-25 20:18:00 -05:00
parent 67e74cbdd1
commit 7c8f22ff56
7 changed files with 38 additions and 21 deletions

View File

@ -13,6 +13,7 @@
#include "screen.h" #include "screen.h"
#include "misc.h" #include "misc.h"
#include "event.h" #include "event.h"
#include "balloon.h"
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
@ -156,7 +157,7 @@ void ShapeBalloon( int fx, int fy, int xoff, int yoff, int woff, int hoff, int w
void BalloonSize( int *lh, int *lw, int *offset, int *w, int *h, MlvwmWindow *mw ) void BalloonSize( int *lh, int *lw, int *offset, int *w, int *h, MlvwmWindow *mw )
{ {
int lp; int lp;
char contents[256]; char contents[MAX_BALLOON_STR_LEN];
int contents_width=0, strw, strh; int contents_width=0, strw, strh;
int xinc, yinc; int xinc, yinc;
@ -223,7 +224,7 @@ void BalloonSize( int *lh, int *lw, int *offset, int *w, int *h, MlvwmWindow *mw
void DrawWindowBalloon( int xoff, int yoff, int lh, int offset, int lw, MlvwmWindow *mw ) void DrawWindowBalloon( int xoff, int yoff, int lh, int offset, int lw, MlvwmWindow *mw )
{ {
int lp; int lp;
char contents[255]; char contents[MAX_BALLOON_STR_LEN];
int xinc, yinc; int xinc, yinc;
for( lp=0; WinLabel[lp]!=NULL; lp++ ){ for( lp=0; WinLabel[lp]!=NULL; lp++ ){

View File

@ -8,5 +8,7 @@
#ifndef _BALLOON_ #ifndef _BALLOON_
#define _BALLOON_ #define _BALLOON_
#define MAX_BALLOON_STR_LEN 255
extern void BalloonHelp( void ); extern void BalloonHelp( void );
#endif /* _BALLOON_ */ #endif /* _BALLOON_ */

View File

@ -966,6 +966,7 @@ void DrawAllDecorations( MlvwmWindow *t, Bool on_off )
void SetFocus( MlvwmWindow *t ) void SetFocus( MlvwmWindow *t )
{ {
char *str, action[24], *winname; char *str, action[24], *winname;
size_t str_size;
unsigned long mask, valuemask; unsigned long mask, valuemask;
XSetWindowAttributes attributes; XSetWindowAttributes attributes;
XGCValues xgcv; XGCValues xgcv;
@ -1016,8 +1017,9 @@ void SetFocus( MlvwmWindow *t )
ChangeMenuLabel( &(Scr.IconMenu), NULL, ChangeMenuLabel( &(Scr.IconMenu), NULL,
t->miniicon==NULL?Scr.SystemIcon:t->miniicon ); t->miniicon==NULL?Scr.SystemIcon:t->miniicon );
if( !(t->flags&TRANSIENT) ){ if( !(t->flags&TRANSIENT) ){
str = calloc( strlen(t->name)+6, 1 ); str_size = strlen(t->name)+6;
sprintf( str, "Hide %s", t->name ); str = calloc( str_size, 1 );
snprintf( str, str_size, "Hide %s", t->name );
ChangeMenuItemLabel( "ICON", Scr.IconMenu.m_item->label, ChangeMenuItemLabel( "ICON", Scr.IconMenu.m_item->label,
str, NULL, SELECTON, M_COPY ); str, NULL, SELECTON, M_COPY );
ChangeMenuItemLabel( "ICON", "Hide Others", "Hide Others", ChangeMenuItemLabel( "ICON", "Hide Others", "Hide Others",

View File

@ -761,6 +761,7 @@ void ReadConfigFile( char *configfile )
int lp; int lp;
#ifdef MLVWMLIBDIR #ifdef MLVWMLIBDIR
char *sysrc; char *sysrc;
size_t sysrc_size;
#endif #endif
if( (file = LookUpFiles( NULL, configfile, R_OK ))==NULL ) if( (file = LookUpFiles( NULL, configfile, R_OK ))==NULL )
@ -768,12 +769,14 @@ void ReadConfigFile( char *configfile )
#ifdef MLVWMLIBDIR #ifdef MLVWMLIBDIR
if( !file ){ if( !file ){
if( strcmp( configfile, CONFIGNAME) ){ if( strcmp( configfile, CONFIGNAME) ){
sysrc = calloc( strlen(MLVWMLIBDIR)+strlen(configfile)+2, 1 ); sysrc_size = strlen(MLVWMLIBDIR)+strlen(configfile)+2;
sprintf( sysrc, "%s/%s", MLVWMLIBDIR, configfile ); sysrc = calloc( sysrc_size, 1 );
snprintf( sysrc, sysrc_size, "%s/%s", MLVWMLIBDIR, configfile );
} }
else{ else{
sysrc = calloc( strlen(MLVWMLIBDIR)+strlen(configfile)+9, 1 ); sysrc_size = strlen(MLVWMLIBDIR)+strlen(configfile)+9;
sprintf( sysrc, "%s/system%s", MLVWMLIBDIR, configfile ); sysrc = calloc( sysrc_size, 1 );
snprintf( sysrc, sysrc_size, "%s/system%s", MLVWMLIBDIR, configfile );
} }
file = LookUpFiles( NULL, sysrc, R_OK ); file = LookUpFiles( NULL, sysrc, R_OK );
free( sysrc ); free( sysrc );

View File

@ -1596,6 +1596,7 @@ void handle_property_request( XEvent *ev )
XTextProperty text_prop; XTextProperty text_prop;
unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth; unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth;
char desk[8], *str, action[24]; char desk[8], *str, action[24];
size_t str_size;
#ifdef USE_LOCALE #ifdef USE_LOCALE
int num; int num;
char **list; char **list;
@ -1640,8 +1641,9 @@ void handle_property_request( XEvent *ev )
ChangeMenuItemLabel( "ICON", oldWinName, winname, ChangeMenuItemLabel( "ICON", oldWinName, winname,
action, M_ALLSET, M_AND ); action, M_ALLSET, M_AND );
if( tmp_win==Scr.ActiveWin ){ if( tmp_win==Scr.ActiveWin ){
str = calloc( strlen( tmp_win->name )+6, 1 ); str_size = strlen(tmp_win->name)+6;
sprintf( str, "Hide %s", tmp_win->name ); str = calloc( str_size, 1 );
snprintf( str, str_size, "Hide %s", tmp_win->name );
ChangeMenuItemLabel( "ICON", Scr.IconMenu.m_item->label, ChangeMenuItemLabel( "ICON", Scr.IconMenu.m_item->label,
str, NULL, SELECTON, M_COPY ); str, NULL, SELECTON, M_COPY );
free( str ); free( str );

View File

@ -43,7 +43,8 @@ char *fgetline( char *str, int size, FILE *fp )
char *LookUpFiles( char *path, char *filename, int mode ) char *LookUpFiles( char *path, char *filename, int mode )
{ {
char *find; char *find, *separator;
size_t find_size;
if( !access( filename, mode ) ){ if( !access( filename, mode ) ){
find = strdup( filename ); find = strdup( filename );
@ -52,14 +53,16 @@ char *LookUpFiles( char *path, char *filename, int mode )
if( path==NULL ) return NULL; if( path==NULL ) return NULL;
do{ do{
path=SkipSpace( path ); path=SkipSpace( path );
find = calloc( strlen(path)+strlen(filename)+2, 1 ); find_size = strlen(path)+strlen(filename)+2;
find = calloc( find_size, 1 );
if( strchr( path, ':' )==NULL ){ if( strchr( path, ':' )==NULL ){
sprintf( find, "%s/%s", path, filename ); snprintf( find, find_size, "%s/%s", path, filename );
path += strlen( path ); path += strlen( path );
} }
else{ else{
strcpy( find, path ); strcpy( find, path );
sprintf( strchr( find, ':' ), "/%s", filename ); separator = strchr( find, ':' );
snprintf( separator, strlen(separator)+strlen(filename)+2, "/%s", filename );
path = strchr( path, ':') + 1; path = strchr( path, ':') + 1;
} }
if( !access(find, mode ) ){ if( !access(find, mode ) ){
@ -120,12 +123,14 @@ void sleep_a_little(int n)
void DrawErrMsgOnMenu( char *str1, char *str2 ) void DrawErrMsgOnMenu( char *str1, char *str2 )
{ {
char *str; char *str;
size_t str_size;
static int call=0; static int call=0;
int wait_s; int wait_s;
call++; call++;
str = calloc( strlen(str1)+strlen(str2)+1, 1 ); str_size = strlen(str1)+strlen(str2)+1;
sprintf( str, "%s%s", str1, str2 ); str = calloc( str_size, 1 );
snprintf( str, str_size, "%s%s", str1, str2 );
if( call<5 ) XBell( dpy, 30 ); if( call<5 ) XBell( dpy, 30 );
DrawStringMenuBar( str ); DrawStringMenuBar( str );
wait_s = 3000000-call/5*500000; wait_s = 3000000-call/5*500000;
@ -274,13 +279,15 @@ void RaiseMlvwmWindow( MlvwmWindow *win )
char *WinListName( MlvwmWindow *mw ) char *WinListName( MlvwmWindow *mw )
{ {
char *winname; char *winname;
size_t winname_size;
winname = calloc( strlen( mw->name )+1+(Scr.flags&DISPDESK?3:0), 1 ); winname_size = strlen( mw->name )+1+(Scr.flags&DISPDESK?3:0);
winname = calloc( winname_size, 1 );
if( Scr.flags&DISPDESK ){ if( Scr.flags&DISPDESK ){
if( mw->flags&STICKY ) if( mw->flags&STICKY )
sprintf( winname, "S:%s", mw->name ); snprintf( winname, winname_size, "S:%s", mw->name );
else else
sprintf( winname, "%d:%s", mw->Desk, mw->name ); snprintf( winname, winname_size, "%d:%s", mw->Desk, mw->name );
} }
else else
strcpy( winname, mw->name ); strcpy( winname, mw->name );

View File

@ -614,7 +614,7 @@ int main( int argc, char *argv[] )
if(!single){ if(!single){
for(lp=0;lp<Scr.NumberOfScreens;lp++){ for(lp=0;lp<Scr.NumberOfScreens;lp++){
if(lp!= Scr.screen){ if(lp!= Scr.screen){
sprintf(message,"%s -d %s",argv[0],XDisplayString(dpy)); snprintf(message, sizeof(message), "%s -d %s", argv[0], XDisplayString(dpy));
len = strlen(message); len = strlen(message);
message[len-1] = '\0'; message[len-1] = '\0';
sprintf(num,"%d",lp); sprintf(num,"%d",lp);
@ -633,7 +633,7 @@ int main( int argc, char *argv[] )
} }
len = strlen( XDisplayString( dpy ) ); len = strlen( XDisplayString( dpy ) );
display_string = calloc( len+10, sizeof( char ) ); display_string = calloc( len+10, sizeof( char ) );
sprintf( display_string, "DISPLAY=%s", XDisplayString( dpy ) ); snprintf( display_string, len+10, "DISPLAY=%s", XDisplayString(dpy) );
putenv( display_string ); putenv( display_string );
XShapeQueryExtension( dpy, &ShapeEventBase, &ShapeErrorBase ); XShapeQueryExtension( dpy, &ShapeEventBase, &ShapeErrorBase );