This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Bug in windres?
- From: Linus Nielsen Feltzing <linus at haxx dot se>
- To: binutils at sources dot redhat dot com
- Date: Thu, 01 Jul 2004 01:14:04 +0200
- Subject: Bug in windres?
Hi all!
(first post to the list)
Some time ago, I worked on a small MinGW program, which created a small
menu in a resource file. When I compiled it using windres, the menu was
corrupt. I have absolutely no clue about Windows resources, but by
comparing with the output of other resource compilers I found that the
MENUEX structure was too small in the windres output.
I changed resbin.c to correct the problem, but I have no idea if I did
it correctly, or if I broke something else by doing it.
Could someone with some knowledge comment on this?
Regards,
Linus Nielsen Feltzing
--------< The resource script >---------
#include <windows.h>
#include "hotres.h"
IDI_HOTRES ICON hotfolder.ico
IDM_CONTEXTMAIN MENUEX DISCARDABLE
BEGIN
POPUP "You'll never see this", IDM_CONTEXTPOPUP
BEGIN
MENUITEM "E&xit", IDM_EXIT, MFT_STRING, MFS_ENABLED
END
END
-------------< end >--------------
-------------< The patch >--------------
Index: resbin.c
===================================================================
RCS file: /cvs/src/src/binutils/resbin.c,v
retrieving revision 1.7
diff -u -r1.7 resbin.c
--- resbin.c 14 Sep 2003 12:20:16 -0000 1.7
+++ resbin.c 30 Jun 2004 23:10:35 -0000
@@ -380,7 +380,7 @@
unsigned int itemlen;
struct menuitem *mi;
- if (length < 14)
+ if (length < 16)
toosmall (_("menuitem header"));
mi = (struct menuitem *) res_alloc (sizeof *mi);
@@ -388,17 +388,17 @@
mi->state = get_32 (big_endian, data + 4);
mi->id = get_16 (big_endian, data + 8);
- flags = get_16 (big_endian, data + 10);
+ flags = get_16 (big_endian, data + 12);
- if (get_16 (big_endian, data + 12) == 0)
+ if (get_16 (big_endian, data + 14) == 0)
{
slen = 0;
mi->text = NULL;
}
else
- mi->text = get_unicode (data + 12, length - 12, big_endian, &slen);
+ mi->text = get_unicode (data + 14, length - 14, big_endian, &slen);
- itemlen = 12 + slen * 2 + 2;
+ itemlen = 14 + slen * 2 + 2;
itemlen = (itemlen + 3) &~ 3;
if ((flags & 1) == 0)
@@ -1874,21 +1874,23 @@
dword_align_bin (&pp, &length);
d = (struct bindata *) reswr_alloc (sizeof *d);
- d->length = 12;
- d->data = (unsigned char *) reswr_alloc (12);
+ d->length = 14;
+ d->data = (unsigned char *) reswr_alloc (14);
- length += 12;
+ length += 14;
put_32 (big_endian, mi->type, d->data);
put_32 (big_endian, mi->state, d->data + 4);
put_16 (big_endian, mi->id, d->data + 8);
+ put_16 (big_endian, 0, d->data + 10);
+
flags = 0;
if (mi->next == NULL)
flags |= 0x80;
if (mi->popup != NULL)
flags |= 1;
- put_16 (big_endian, flags, d->data + 10);
+ put_16 (big_endian, flags, d->data + 12);
*pp = d;
pp = &d->next;
-------------< end >--------------