Is GCC mishandling a pointer to a va_list passed to a function?

后端 未结 4 1411
日久生厌
日久生厌 2020-11-30 08:48

The question \'Pass va_list or pointer to va_list?\' has an answer which quotes the standard (ISO/IEC 9899:1999 - §7.15 \'Variable arguments , f

4条回答
  •  一个人的身影
    2020-11-30 09:08

    As others have noted, this issue manifests itself when va_list is an array type. This is allowed by the standard, which only says that va_list must be an "object type".

    You can fix the test_val() function like so:

    static void test_val(const char *fmt, va_list args)
    {
        va_list args_copy;
    
        /* Note: This seemingly unnecessary copy is required in case va_list
         * is an array type. */
        va_copy(args_copy, args);
        test_ptr(fmt, &args_copy);
        va_end(args_copy);
    }
    

提交回复
热议问题