My opinion is to keep it portable. The warning is there for a reason. 
you are worried about performance yet are calling a function that does 
nothing, which will take more memory cycles than a simple check for zero.

Trying to memset a zero length is a bug, not the warning. Add an if 
statement around it. If the variable is local, it will probably be 
optimized as a register variable and a zero check of a register is a 
single op-code.

the problem with disabling warnings is that even if this instance is not 
an error, some other part of the code may end up with the same situation 
but is an error in the coding. I would prefer code that can be compiled 
with all warnings turned on that gives no warnings than have a potential 
problem because of a glitch in the code.

------------
Scott Doctor
scott at scottdoctor.com

On 8/20/2015 9:32 AM, Scott Hess wrote:
> Yeah, we saw this with Chromium, too.  The patch we use is below.
>
> I'm with Dr Hipp that this is really more of a GCC issue.  If it was
> literally a 0 constant, it would make sense to warn so that the code can be
> removed.  But it's only a 0 if you optimize a certain way.
>
> -scott
>
>
> diff --git a/third_party/sqlite/src/src/expr.c
> b/third_party/sqlite/src/src/expr.c
> index 4012f6c..65f211e 100644
> --- a/third_party/sqlite/src/src/expr.c
> +++ b/third_party/sqlite/src/src/expr.c
> @@ -856,7 +856,9 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int flags,
> u8 **pzBuffer){
>         }else{
>           int nSize = exprStructSize(p);
>           memcpy(zAlloc, p, nSize);
> -        memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
> +        if( EXPR_FULLSIZE>nSize ){
> +          memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
> +        }
>         }
>
>         /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags
> appropriately. */
>
>
> On Thu, Aug 20, 2015 at 3:13 AM, Bernhard Schommer <
> bernhardschommer at gmail.com> wrote:
>
>> Hi,
>>
>> the warning which is mentioned in the ticket
>> f51d9501800de5a0fb69d5048ce6662981b461ec still occurs also with newer gcc
>> versions. The ticket was closed after a gcc bug report was opened. The gcc
>> bug was closed due to a missing testcase.
>> I had a quick look at the problem and it seems that the warning is right
>> since in certain context and with optimizations enabled gcc can prove
>> that EXPR_FULLSIZE
>> - nSize == 0 and thus the triggered warning for this is correct.
>> Replacing
>> memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
>> By
>> if(EXPR_FULLSIZE-nSize > 0)
>>       memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
>> would remove the warning,
>>
>> Cheers,
>> -Bernhard
>> _______________________________________________
>> sqlite-users mailing list
>> sqlite-users at mailinglists.sqlite.org
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>

Reply via email to