[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] -Woverlength-strings / assert unhelpful interaction

Richard W.M. Jones wrote:

> $ gcc -O2 -c -Woverlength-strings stupid.c
> stupid.c: In function ‘insert_lf_record’:
> stupid.c:22: warning: string length ‘7394’ is greater than the length ‘509’ ISO C90 compilers are required to support
> Without -O2 the error message goes away.
> Even ISO C99 compilers don't help - they raise the limit to a mere
> 4095 bytes.

Hi Rich,

As you no doubt realize, that is because the expansion of your assert
expression is so long.  Think of it as encouragement to use inline
functions in place of macros whenever possible.
This is a good example of how inline functions are superior,
in addition to the usual more-type-safe argument.  E.g.,

  #define STREQ(a,b) (strcmp(a,b) == 0)

  static inline int
  block_id_eq (const struct hive_h *h, size_t offset, const char *s)
    return STREQ (((struct ntreg_hbin_block *)(h->addr + offset))->id, s);

  static size_t
  insert_lf_record (struct hive_h *h, size_t old_offs, size_t posn,
                    const char *name, hive_node_h node)
    assert (block_id_eq (h, old_offs, "lf") || block_id_eq (h, old_offs, "lh"));

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]