Now that I've got all but one function headerized, I'm running splint.
One of the things that splint is good at, and the reason I did all the
PARROT_CAN(NOT)_RETUN_NULL flags, is it'll keep track of when something
could be NULL or not.  So splint complains here:

char * const p = malloc(n);
p->foo = ...

and not here

char * const p = mem_sys_allocate(n);
p->foo = ...

because mem_sys_allocate() is marked as PARROT_CANNOT_RETURN_NULL.

So I can do this in PackFile_new:

Index: src/packfile.c
===================================================================
--- src/packfile.c      (revision 23681)
+++ src/packfile.c      (working copy)
@@ -1119,24 +1119,14 @@

PARROT_API
PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
+PARROT_CANNOT_RETURN_NULL
PackFile *
PackFile_new(PARROT_INTERP, INTVAL is_mapped)
{
   PackFile * const pf = mem_allocate_zeroed_typed(PackFile);

-    if (!pf) {
-        PIO_eprintf(NULL, "PackFile_new: Unable to allocate!\n");
-        return NULL;
-    }
   pf->is_mmap_ped = is_mapped;
-
   pf->header = mem_allocate_zeroed_typed(PackFile_Header);
-    if (!pf->header) {
- PIO_eprintf(NULL, "PackFile_new: Unable to allocate header! \n");
-        PackFile_destroy(interp, pf);
-        return NULL;
-    }
   /*
    * fill header with system specific data
    */
Index: include/parrot/packfile.h
===================================================================
--- include/parrot/packfile.h   (revision 23681)
+++ include/parrot/packfile.h   (working copy)
@@ -453,7 +453,7 @@

PARROT_API
PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
+PARROT_CANNOT_RETURN_NULL
PackFile * PackFile_new(PARROT_INTERP, INTVAL is_mapped)
       __attribute__nonnull__(1);



The other thing to come out of this instrumentation is when splint tells
us that we can be dereferencing NULL, as in here:

intlist_get(PARROT_INTERP, NOTNULL(IntList *list), INTVAL idx)
{
  /* XXX list_get can return NULL RT #48367 */
void * const ret = list_get(interp, (List *)list, idx, enum_type_INTVAL);
  const INTVAL retval = ret == (void *)-1 ? 0 : *(INTVAL *)ret;

ret could be NULL, but we're not checking that, so it's possible to
de-refernece a NULL.

So that's what I'm workin' on, running splint, fixing headerizations,
etc.  Let me know if anything shakes loose, or looks crazy, or causes
problems with your specific compiler.  I'd especially like it if someone
non-GCC has compiler options that we can put into
PARROT_CANNOT_RETURN_NULL and its brethren so we have more compilers
watching our backs.

xoxo,
Andy

--
Andy Lester => [EMAIL PROTECTED] => www.petdance.com => AIM:petdance

Reply via email to