Hi,

> I'm weeding out Purify bugs slowly but surely, but ran into two I'm not
> sure what to do about:
> 
> #1 ----------------------
>         resourceLoader [resource.c:291]
>                 if (base.resource)
>                     while (seeker) {
>                         memcpy(resource_map + resourceCounter, seeker->resource,
>          =>                    sizeof(resource_t));
>                         resourceCounter++;
>                         seeker = seeker->next;
>                     }

That's almost certainly caused by the new members of resource_t, which
are neither read from nor written to- they're intended to be used with the
LRU resource manager.
Unless I'm missing something, this one should be OK.


> #2 ---------------------------------
> I fixed this by initializing conf after the malloc. The original warning
> was:
> 
> [W] UMC: Uninitialized memory copy in memcpy {1 occurrence}
>         Copying 208 bytes from 0x02b623b8 (4 bytes at 0x02b623ec
> uninitialized)
>         Address 0x02b623b8 is at the beginning of a 416 byte block
>         Address 0x02b623b8 points to a malloc'd block in heap 0x02b60000
>         Thread ID: 0x45c
>         Error location
>             memcpy         [memcpy.obj]
>             UnnamedFunction [config.l:270]
>                     conf = sci_realloc(conf, sizeof(config_entry_t) * (cur_section + 
>1));
> 
>                     /* ...and initialize it */
>              =>     memcpy(&(conf[cur_section]), &(conf[0]), sizeof(config_entry_t));
> 
> 
> After memset'ing conf to 0, I then get:

Don't do this in practice, BTW. If we're really missing some 
initialization here, you'll be setting the entry we forgot to initialize,
and zero might not be the correct default value for it.
A better way to do initialization would probably be to fill out an entire
config_entry_t structure statically, and use that instead- this way,
missing entries would be easy to track. OTOH, adding new entries to
config_entry_t might cause trouble.

In order to keep the initialization close to the structure definition, we
could do something like the following:

-- sci_config.h:
....

typedef struct {
        ...
} config_entry_t;

#ifdef USE_DEFAULT_CONFIG_ENTRY /* COMMENT */
static config_entry_t default_config = {
        ...
};
#endif

....
-- config.l:
....

#define USE_DEFAULT_CONFIG_ENTRY /* COMMENT */
#include <sci_config.h> /* COMMENT */

....
----

> [E] NPR: NULL pointer read in stricmp {1 occurrence}
> 
>     read_config    [main.c:544]
>  =>         if (!strcasecmp((*conf)[i].name, game_name)) {

Is 'i' zero here? This could be the first entry, whose name is NULL. I
don't have the sources available ATM, so I'm not sure what we should be
doing if the name is NULL (which itself is perfectly fine, provided thtat
we're really talking about configuration #0 here).

Thanks for finding this one!


llap,
 Christoph


Reply via email to