我要评分
获取效率
正确性
完整性
易理解

upb.c Compilation Syntax Error Reported During TensorFlow Serving Compilation

Symptom

During TensorFlow Serving compilation, an error message is displayed, indicating that the upb.c file fails to be compiled. The error message is "'__builtin_strncpy' specified bound 127 equals destination size [-Werror=stringop-truncation]." The details are as follows:

WARNING: errors encountered while analyzing target '//tensorflow_serving/model_servers:tensorflow_model_server': it will not be built
In file included from /usr/include/string.h:519,
                 from external/upb/upb/upb.h:16,
                 from external/upb/upb/upb.c:2:
In function 'strncpy',
    inlined from 'upb_status_seterrmsg' at external/upb/upb/upb.c:40:3:
/usr/include/bits/string_fortified.h:95:10: error: '__builtin_strncpy' specified bound 127 equals destination size [-Werror=stringop-truncation]
   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |       __glibc_objsize (__dest));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Target //tensorflow_serving/model_servers:tensorflow_model_server failed to build

Key Process and Cause Analysis

The strncpy function is incorrectly used, and TensorFlow Serving does not update the upb version in a timely manner.

Conclusion and Solution

  1. Search for strncpy(status->msg, msg, sizeof(status->msg)) in files in the current directory and all its subdirectories.
    1
    grep -nr "strncpy(status->msg, msg, sizeof(status->msg));"
    
  2. Replace it with strncpy(status->msg, msg, sizeof(status->msg)-1);.
    1
    find . -type f -name "*.c" -o -name "*.h" | xargs grep -l 'strncpy(status->msg, msg, sizeof(status->msg));' | xargs sed -i 's/strncpy(status->msg, msg, sizeof(status->msg));/strncpy(status->msg, msg, sizeof(status->msg)-1);/g'
    
  3. Run the compile command again.