diff extensions/app_diameap/diameap_server.c @ 1442:915450ee91c7

fix gcc 9.1.1 compile warnings Use snprintf instead of strncpy to ensure NUL termination. Simplify attribute copying to calloc/memcpy instead of malloc/memset/strncpy/assignment. Appeases gcc 9.1.1 warnings about strncpy bounds.
author Luke Mewburn <luke@mewburn.net>
date Thu, 27 Feb 2020 16:19:24 +1100
parents 0918e88f7c33
children
line wrap: on
line diff
--- a/extensions/app_diameap/diameap_server.c	Tue Feb 25 10:42:08 2020 +1100
+++ b/extensions/app_diameap/diameap_server.c	Thu Feb 27 16:19:24 2020 +1100
@@ -1960,22 +1960,16 @@
 	switch (*toadd)
 	{
 	case 1:
-		attribute_op = malloc(strlen(op));
-		memset(attribute_op, 0, strlen(op));
-		strncpy(attribute_op, op + 1, strlen(op) - 1);
-		attribute_op[strlen(op)] = '\0';
+		attribute_op = calloc(strlen(op), sizeof(char *));
+		memcpy(attribute_op, op + 1, strlen(op) - 1);
 		break;
 	case 2:
-		attribute_op = malloc(strlen(op));
-		memset(attribute_op, 0, strlen(op));
-		strncpy(attribute_op, op, strlen(op) - 1);
-		attribute_op[strlen(op)] = '\0';
+		attribute_op = calloc(strlen(op), sizeof(char *));
+		memcpy(attribute_op, op, strlen(op) - 1);
 		break;
 	default:
-		attribute_op = malloc(strlen(op) + 1);
-		memset(attribute_op, 0, strlen(op) + 1);
-		strcpy(attribute_op, op);
-		attribute_op[strlen(op) + 1] = '\0';
+		attribute_op = calloc(strlen(op) + 1, sizeof(char *));
+		memcpy(attribute_op, op, strlen(op));
 	}
 	if (strcmp(attribute_op, "=") == 0)
 	{
"Welcome to our mercurial repository"