Skip to content

Commit 95aa77a

Browse files
Use rtapi_strlcpy() instead of strncpy() to avoid compiler warning
The rtapi_strlcpy() method is already used elsewhere in the file, so this do not introduce a new dependency. This fixes the following compiler warning: Compiling libnml/rcs/rcs_print.cc In file included from /usr/include/string.h:495, from libnml/rcs/rcs_print.cc:21: In function ‘char* strncpy(char*, const char*, size_t)’, inlined from ‘int rcs_vprint(const char*, __va_list_tag*, int)’ at libnml/rcs/rcs_print.cc:311:9: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 99 bytes from a string of length 255 [-Wstringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Adjust size from 99 to 100, to match strlcpy() sematics and the 100 byte size of last_error_bufs[][].
1 parent bd3b279 commit 95aa77a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libnml/rcs/rcs_print.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ int rcs_vprint(const char *_fmt, va_list _args, int save_string)
308308
}
309309
last_error_buf_filled++;
310310
last_error_buf_filled %= 4;
311-
strncpy(last_error_bufs[last_error_buf_filled], temp_string, 99);
311+
rtapi_strlcpy(last_error_bufs[last_error_buf_filled], temp_string, 100); // 100 or sizeof(temp_string)?
312312
}
313313
return (rcs_fputs(temp_string));
314314
}

0 commit comments

Comments
 (0)