Branch: Tag:

2019-11-14

2019-11-14 23:29:42 by Tobias S. Josefowitz <tobij@tobij.de>

Optimizer: Make Coverity happier

Coverity does not like us using the result of arguments(1) ($1a) as
array index, as arguments() could in theory return -1. Guarding against
that seems not possible in peep.in rules, so we now instead just call to
a function added to peep.c that performs the check in a (hopefully)
Coverity-approved way [CID 1455693].

This is probably not a very elegant solution, however I assume guarding
in the form of [$1a >= 0 && ...] would not make Coverity happy since it
probably cannot infer that arguments(1) returns the same value both
times. But I really do not know the extent of Coverity's magic here.

835:   static inline int opcode(int offset);   static inline int argument(int offset);   static inline int argument2(int offset); + static inline unsigned int check_local_var_flag(int var, int flag);      #include "peep_engine.c"   
952:    return -1;   }    + /* This is used from two peep.in rules, merely because coverity did not +  * like accessing ...->variables[arguments(1)], as arguments() could in theory +  * return a negative value. Neither very pretty nor generic... */ + static inline unsigned int check_local_var_flag(int var, int flag) + { +  if (var >= 0) +  return Pike_compiler->compiler_frame->variable[var].flags & flag; +  +  return 0; + } +  +    static int advance(void)   {    p_instr *p;