Commit 1c2c007a authored by Vaibhav Gupta's avatar Vaibhav Gupta Committed by Federico Vaga

software: tools: fau-tg-config: Fix "[-Werror=stringop-truncation]"

"strncat" needs the size of buffer that has to be concatenated, as its
3rd argument.

In function,
	"int fau_write_attribute(enum fau_attribute attr, uint32_t val)"

"strncat" when called for the second time is being overflowed. Fix that.
The goal that this code is trying to achieve can be done in one line
with "snprintf".
Signed-off-by: 's avatarVaibhav Gupta <vaibhav.gupta@cern.ch>
Reviewed-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 713a5105
......@@ -63,10 +63,8 @@ int fau_write_attribute(enum fau_attribute attr, uint32_t val)
/* convert val to string */
snprintf(buf, buf_len, "%u",val);
/* build the attribute path */
strncpy(fullpath, basepath, path_len);
if (path_len > 0)
fullpath[path_len -1] = '\0';
strncat(fullpath, attribute[attr], path_len);
snprintf(fullpath, path_len, "%s%s", basepath, attribute[attr]);
/* Write the attribute */
printf("Writing %s in %s\n", buf, fullpath);
fd = open(fullpath, O_WRONLY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment