---
title: 编译TensorFlow Serving时提示upb.c编译语法错误
description: "编译TensorFlow Serving时提示upb.c文件编译出错，报错信息为“'__builtin_strncpy' specified bound 127 equals destination size [-Werror=stringop-truncation]”。详细信息如下所示。"
url: https://www.hikunpeng.com/document/detail/zh/SRA/perfEval/benchmarksra/kunpengmodelzoo_06_0020.html
sourcePath: /source/zh/SRA/perfEval/benchmarksra/kunpengmodelzoo_06_0020.html
indexId: 2b5ec158b42a29ab72996160a1f9493b7f0d874b16e99051c28493fc0130856665
---
# 编译TensorFlow Serving时提示upb.c编译语法错误

#### 问题现象描述

编译TensorFlow Serving时提示upb.c文件编译出错，报错信息为“'__builtin_strncpy' specified bound 127 equals destination size [-Werror=stringop-truncation]”。详细信息如下所示。

```
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
```


#### 关键过程、根本原因分析

strncpy函数误用。TensorFlow Serving未及时更新upb版本。


#### 结论、解决方案及效果

1. 在当前目录及所有子目录的文件中搜索“strncpy(status->msg, msg, sizeof(status->msg));”。
  1 grep -nr "strncpy(status->msg, msg, sizeof(status->msg));"

2. 替换为“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. 重新执行编译命令。
