unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ben Key" <Bkey1@tampabay.rr.com>
Subject: Fix for Emacs Crash
Date: Wed, 6 Nov 2002 23:05:16 -0500	[thread overview]
Message-ID: <002101c28612$e1e15710$6501a8c0@GODDESS> (raw)

[-- Attachment #1: Type: text/plain, Size: 3046 bytes --]

The following patch fixes a bug I experienced when running a build of GNU
Emacs I made on Windows XP SP1 on Windows 2000 SP2.  The crash occurred when
starting Emacs.

<patch>
--- _21.3/src/w32menu.c	2002-08-05 12:33:44.000000000 -0400
+++ 21.3/src/w32menu.c	2002-11-06 23:01:11.000000000 -0500
@@ -2215,9 +2215,11 @@
 	      info.fState = wv->selected ? MFS_CHECKED : MFS_UNCHECKED;
 	    }

-	  set_menu_item_info (menu,
-			      item != NULL ? (UINT) item : (UINT) wv->call_data,
-			      FALSE, &info);
+    set_menu_item_info (
+        menu,
+        item != NULL ? (UINT) item : (UINT) wv->call_data,
+        item != NULL ? FALSE : TRUE,
+        &info);
 	}
     }
   return return_value;
</patch>

The logic behind this patch is as follows:
* The documentation of SetMenuItemInfo from the MSDN Library is as follows:
  SetMenuItemInfo
  The SetMenuItemInfo function changes information about a menu item.

  BOOL SetMenuItemInfo(
    HMENU hMenu, // handle to menu
    UINT uItem, // identifier or position
    BOOL fByPosition, // meaning of uItem
    LPMENUITEMINFO lpmii // menu item information
    );
  Parameters
    hMenu
      [in] Handle to the menu that contains the menu item.
    uItem
      [in] Identifier or position of the menu item to change.
      The meaning of this parameter depends on the value of
      fByPosition.
    fByPosition
      [in] Value specifying the meaning of uItem. If this
      parameter is FALSE, uItem is a menu item identifier.
      Otherwise, it is a menu item position.
    lpmii
      [in] Pointer to a MENUITEMINFO structure that contains
      information about the menu item and specifies which menu
      item attributes to change.

  Return Values
    If the function succeeds, the return value is nonzero.

    If the function fails, the return value is zero. To get
    extended error information, use the GetLastError function.

* I interpreted the line
  item != NULL ? (UINT) item : (UINT) wv->call_data,
to mean if item is not NULL, use the specified menu identifier, otherwise
use the position specified by the call_data member of the wv structure.

* Based upon this interpretation, passing SetMenuItemInfo a value of FALSE
for the fByPosition parameter unconditionally is obviously incorrect.
Instead fByPosition should only be FALSE if item is non NULL.

Please let me know if my logic behind this fix is flawed.  I am not
absolutely certain that the call_data member of the wv structure is supposed
to the position index if the item in the menu because I have not yet
determined how its value is getting set.

I have tested this fix by successfully running a build of Emacs done on a
Windows XP machine using MSVC 6.0 on Windows 2000.

NOTE: I have no idea why this crash only occurred when running Emacs on a
version of Windows other than the one on which it was built.  All I know is
that when I remote debugged Emacs to determine why I could not run the build
I did on Windows XP on Windows 2000, Emacs crashed on this function call and
item at that point was NULL.


[-- Attachment #2: 21_3-w32menu.c.diff --]
[-- Type: application/octet-stream, Size: 542 bytes --]

--- _21.3/src/w32menu.c	2002-08-05 12:33:44.000000000 -0400
+++ 21.3/src/w32menu.c	2002-11-06 23:01:11.000000000 -0500
@@ -2215,9 +2215,11 @@
 	      info.fState = wv->selected ? MFS_CHECKED : MFS_UNCHECKED;
 	    }
 
-	  set_menu_item_info (menu,
-			      item != NULL ? (UINT) item : (UINT) wv->call_data,
-			      FALSE, &info);
+    set_menu_item_info (
+        menu,
+        item != NULL ? (UINT) item : (UINT) wv->call_data,
+        item != NULL ? FALSE : TRUE,
+        &info);
 	}
     }
   return return_value;

             reply	other threads:[~2002-11-07  4:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-07  4:05 Ben Key [this message]
2002-11-07 19:47 ` Fix for Emacs Crash Jason Rumney
2002-11-07 20:28   ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2002-11-07 21:26 bkey1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='002101c28612$e1e15710$6501a8c0@GODDESS' \
    --to=bkey1@tampabay.rr.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).