home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!decwrl!netsys!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsc!cbfsb!att-out!rutgers!spcvxb!4carroll_j
- From: 4carroll_j@spcvxb.spc.edu
- Newsgroups: comp.windows.x
- Subject: Invalid Code Assumptions in Xt Code
- Message-ID: <1992Nov6.164950.4337@spcvxb.spc.edu>
- Date: 6 Nov 92 21:49:50 GMT
- Organization: St. Peter's College, US
- Lines: 47
-
-
- Hi,
-
- I don't know who to inform about bugs in the X11R5 distribution, but I
- have found two today. Both bugs are due to the same oversight on the part
- of the programmer, and both problems relate to the X-Toolkit library.
- Someone it seems has made the mistaken assumption that sizeof(int) ==
- sizeof(long).
-
- The first example of where this is a problem in the module Resources.c
- in the Xt library. The function _XtDependencies() casts a XtResourceList to
- a XrmResourceList. If you examine the respective definitions of these two
- objects you will see that the 5th field of the XtResourceList is a Cardinal
- object (typedef'ed as an unsigned int), and the 5th field of the
- XrmResourceList is a long int object. This makes structure pointer
- arithmatic performed later invalid.
-
- To correct this situation, you must alter one of the definitions to
- match the other. I have opted to change the long int declaration in the
- XrmResourceList object to a Cardinal. Hopefully this will work.
-
- The second mistake is more complicated, but stems from the same
- erroneous assumption. It is also in the Xt library, but is in the Error.c
- module. There are two methods meant to provide default error handling,
- _XtDefaultErrorMsg() and _XtDefaultWarningMsg(). Both of these methods
- invoke the sprintf method (the invokation is the problem).
-
- The first thing that each function does is set up a locale String
- parm[10] object, and initialize it with the variable arguments passed. The
- sprintf function is then called, with each of the 10 String objects being
- passed as parameters. The problem ocurrs if the format string passed to the
- method specifies %d. The sprintf method (on a 16-bit machine), will assume
- that 16 bits are on the stack, and bump the va_list pointer to the next
- stack object. Since String objects are actually typedef'ed char pointers
- (which work out to 32-bits in compact, large and huge memory models) the
- sprintf method will not have bumped passed the arg. The next arg fetch
- using va_arg(), will retrieve bad data.
-
- The only way to solve this problem is to write a custom sprintf
- function, and replace all calls to the library sprintf to this sprintf. The
- custom method may then retrieve each parameter as a 32-bit object, but only
- use what portion of it it needs.
-
- Please Forward all comments to Me
-
- Jim Carroll
-
-