[Poppler-bugs] [Bug 21412] New: Bad error handling practice

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Sun Apr 26 04:50:00 PDT 2009


http://bugs.freedesktop.org/show_bug.cgi?id=21412

           Summary: Bad error handling practice
           Product: poppler
           Version: unspecified
          Platform: Other
        OS/Version: Linux (All)
            Status: NEW
          Severity: major
          Priority: high
         Component: general
        AssignedTo: poppler-bugs at lists.freedesktop.org
        ReportedBy: igorenbein at finjan.com


Hello!

At Object.h we have two macros:

#define OBJECT_TYPE_CHECK(wanted_type) \
    if (unlikely(type != wanted_type)) { \
        error(0, "Call to Object where the object was type %d, " \
                 "not the expected type %d", type, wanted_type); \
        abort(); \
    }

#define OBJECT_2TYPES_CHECK(wanted_type1, wanted_type2) \
    if (unlikely(type != wanted_type1) && unlikely(type != wanted_type2)) { \
        error(0, "Call to Object where the object was type %d, " \
                 "not the expected type %d or %d", type, wanted_type1,
wanted_type2); \
        abort(); \
    }

The purpose of these macros is obvious. But, in case of type inconsistency it
is too stiff to abort the WHOLE hosting application. I suggest handling it
either using template functions or treatment per case. For example:

Instead of: 
Dict *getDict() { OBJECT_TYPE_CHECK(objDict); return dict; }

Dict *getDict() 
{
         if (unlikely(type != wanted_type)) 
        { 
                error(0, "Call to Object where the object was type %d, "  "not
the expected type %d", type, wanted_type); 
                return NULL;
         }

         return dict; 
}


Please, let me know if this approach is acceptable to you, and if “yes” I
can supply the patch.


Regards,
Ilya Gorenbein


-- 
Configure bugmail: http://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Poppler-bugs mailing list