Skip to content

Commit

Permalink
Fixed a number of potential dereferenced null pointers in menu.c's pr…
Browse files Browse the repository at this point in the history
…ess_menu() & ChoiseMenu(), as identified by clang scan-build. Issue #48
  • Loading branch information
morgant committed Sep 2, 2024
1 parent 99bf7df commit f3a80b3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions mlvwm/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,11 @@ Bool ChoiseMenu( MenuLabel *m, Window *entwin, int ignore, Bool side )
case EnterNotify:
if( XFindContext( dpy, Event.xcrossing.window, MenuContext,
(caddr_t *)&tmp_menu )!=XCNOENT ){
if( tmp_menu==mapped ){
if( mapped && (mapped == tmp_menu) ) {
finishall = ChoiseMenu( mapped, entwin, ignore, ChildSide );
if( *entwin!=m->PullWin ) isEnd = True;
if ( entwin && (*entwin != m->PullWin) ) isEnd = True;
}
else if( tmp_menu!=m || Event.xcrossing.window==m->LabelWin ){
else if( m && ((tmp_menu != m) || (Event.xcrossing.window == m->LabelWin)) ) {
isEnd = True;
*entwin = Event.xcrossing.window;
if( m->SelectNum != -1 ){
Expand Down Expand Up @@ -548,6 +548,7 @@ Bool ChoiseMenu( MenuLabel *m, Window *entwin, int ignore, Bool side )
else ignore++;
break;
case MotionNotify:
if ( !m ) break;
if(isRect( Event.xbutton.x, Event.xbutton.y, 0, 0,
m->MenuWidth, m->MenuHeight ) &&
Event.xany.window == m->PullWin ){
Expand Down Expand Up @@ -589,7 +590,7 @@ Bool ChoiseMenu( MenuLabel *m, Window *entwin, int ignore, Bool side )
UnmapMenu( mapped, UNMAP_ALL );
DrawMenuItemAll( m );
}
if( Release && m->SelectNum!=-1 ){
if ( Release && m && (m->SelectNum != -1) ) {
UnGrabEvent();
ExecMenu( m, m->SelectNum );
if( !GrabEvent( DEFAULT ) ){
Expand All @@ -608,7 +609,7 @@ void press_menu( MenuLabel *m )
MenuLabel *mapped, *tmp_menu;
int x, y, JunkX, JunkY;
unsigned int JunkMask;
Window JunkRoot, JunkChild, entwin;
Window JunkRoot, JunkChild, entwin = 0;
int ignore;

if( m!=NULL )
Expand Down Expand Up @@ -644,7 +645,7 @@ void press_menu( MenuLabel *m )
if( XFindContext( dpy, Event.xcrossing.window,
MenuContext, (caddr_t *)&tmp_menu )
!=XCNOENT ){
if( mapped != tmp_menu ){
if ( !mapped || (mapped && (mapped != tmp_menu)) ) {
if( mapped ) UnmapMenu( mapped, UNMAP_ALL );
mapped = tmp_menu;
Side = MapMenu( mapped, mapped->LabelX,
Expand All @@ -653,7 +654,7 @@ void press_menu( MenuLabel *m )
}
else if( Event.xcrossing.window==mapped->PullWin ){
isEnd = ChoiseMenu( mapped, &entwin, ignore, Side );
if( entwin == Scr.MenuBar ){
if ( entwin && (entwin == Scr.MenuBar) ) {
UnmapMenu( mapped, UNMAP_ALL );
mapped = NULL;
}
Expand Down

0 comments on commit f3a80b3

Please sign in to comment.