Fix gcc 8 warnings.

This commit is contained in:
Jim Hague 2019-01-15 17:13:13 +00:00
parent 9024fd7736
commit 09ca9a826b
1 changed files with 19 additions and 10 deletions

View File

@ -68,6 +68,15 @@ typedef struct ta_iter {
char digest[2048]; char digest[2048];
} ta_iter; } ta_iter;
static void strcpytrunc(char* dst, const char* src, size_t dstsize)
{
size_t to_copy = strlen(src);
if (to_copy >= dstsize)
to_copy = dstsize -1;
memcpy(dst, src, to_copy);
dst[to_copy] = '\0';
}
/** /**
* XML convert DateTime element to time_t. * XML convert DateTime element to time_t.
* [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] * [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm]
@ -190,8 +199,8 @@ static ta_iter *ta_iter_next(ta_iter *ta)
else if (level == 0 && cur) { else if (level == 0 && cur) {
/* <Zone> content ready */ /* <Zone> content ready */
(void) strncpy( ta->zone, value strcpytrunc( ta->zone, value
, sizeof(ta->zone)); , sizeof(ta->zone));
/* Reset to start of <TrustAnchor> */ /* Reset to start of <TrustAnchor> */
cur = NULL; cur = NULL;
@ -366,20 +375,20 @@ static ta_iter *ta_iter_next(ta_iter *ta)
DEBUG_ANCHOR("elem end: %s\n", value); DEBUG_ANCHOR("elem end: %s\n", value);
switch (elem_type) { switch (elem_type) {
case KEYTAG: case KEYTAG:
(void) strncpy( ta->keytag, value strcpytrunc( ta->keytag, value
, sizeof(ta->keytag)); , sizeof(ta->keytag));
break; break;
case ALGORITHM: case ALGORITHM:
(void) strncpy( ta->algorithm, value strcpytrunc( ta->algorithm, value
, sizeof(ta->algorithm)); , sizeof(ta->algorithm));
break; break;
case DIGESTTYPE: case DIGESTTYPE:
(void) strncpy( ta->digesttype, value strcpytrunc( ta->digesttype, value
, sizeof(ta->digesttype)); , sizeof(ta->digesttype));
break; break;
case DIGEST: case DIGEST:
(void) strncpy( ta->digest, value strcpytrunc( ta->digest, value
, sizeof(ta->digest)); , sizeof(ta->digest));
break; break;
} }
break; break;