]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commit
common/addr_parsing: refactor safe_cat()
authorKefu Chai <kchai@redhat.com>
Wed, 8 Jul 2020 15:33:36 +0000 (23:33 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 8 Jul 2020 16:35:30 +0000 (00:35 +0800)
commit92f4f3cdd0d5909c1aa75167ebb2e81e161aed07
treec0479e23853e4417d368fa966d30fd706d57874f
parent02fc51deb7f3f635fef41321da03283b165eb7ef
common/addr_parsing: refactor safe_cat()

* add a ROUND_UP_128() macro for calculating the round of to a multiple of
  128.
* instead of using a loop, use ROUND_UP_128() for the new size of *pstr
* rename str2 to src for better readability
* use memcpy() instead of strncpy(), as the size of src string is already known

this change also silences the warning of

ceph/src/common/addr_parsing.c: In function ‘safe_cat’:
ceph/src/common/addr_parsing.c:45:3: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
strncpy((*pstr)+pos, str2, len2);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ceph/src/common/addr_parsing.c:28:14: note: length computed here
int len2 = strlen(str2);
^~~~~~~~~~~~

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/addr_parsing.c