Re: patch: General purpose utility functions used by the JSON data type - Mailing list pgsql-hackers

From Tom Lane
Subject Re: patch: General purpose utility functions used by the JSON data type
Date
Msg-id 29820.1281718931@sss.pgh.pa.us
Whole thread Raw
In response to Re: patch: General purpose utility functions used by the JSON data type  (Joseph Adams <joeyadams3.14159@gmail.com>)
List pgsql-hackers
Joseph Adams <joeyadams3.14159@gmail.com> writes:
> On Fri, Aug 13, 2010 at 10:46 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>> +               if (sub_end + len > e)
>> +               {
>> +                       Assert(false);          /* Clipped multibyte character */
>> +                       break;
>> +               }

> If I simply say Assert(sub_end + len <= e), the function will yield a
> range hanging off the edge of the input string (out of bounds).  The
> five lines include a safeguard against that when assertion checking is
> off.

If you think it is actually likely to happen in practice, then an Assert
is 100% inappropriate.  Throw an actual error instead.  Code that has
provisions for continuing after an Assert failure is wrong by definition.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: patch: General purpose utility functions used by the JSON data type
Next
From: David Fetter
Date:
Subject: Re: patch: General purpose utility functions used by the JSON data type