summaryrefslogtreecommitdiffstats
path: root/metadata-parser.c
diff options
context:
space:
mode:
authorAdrian Salido <salidoa@google.com>2017-03-29 15:58:38 -0700
committerMichael Bestas <mkbestas@lineageos.org>2019-10-23 01:12:56 +0300
commit45df97b4a01aaf7fd6e2df17126bd53e59e0099a (patch)
treecef9de1c2eb070bffc04d8b13fa13c4f7f679e70 /metadata-parser.c
parent92ae28df4f36e790600b0af9834dc41db70b4fe0 (diff)
downloadvendor_qcom_opensource_power-45df97b4a01aaf7fd6e2df17126bd53e59e0099a.tar.gz
vendor_qcom_opensource_power-45df97b4a01aaf7fd6e2df17126bd53e59e0099a.tar.bz2
vendor_qcom_opensource_power-45df97b4a01aaf7fd6e2df17126bd53e59e0099a.zip
power: Fix power hal compiler warnings
Bug: 30432975 Test: compile power hal for walleye without warnings Change-Id: I0d90c26462c662690f8a179250000b9a449a109f
Diffstat (limited to 'metadata-parser.c')
-rw-r--r--metadata-parser.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/metadata-parser.c b/metadata-parser.c
index c9122a4..ffe092b 100644
--- a/metadata-parser.c
+++ b/metadata-parser.c
@@ -34,7 +34,7 @@
#include "metadata-defs.h"
int parse_metadata(char *metadata, char **metadata_saveptr,
- char *attribute, int attribute_size, char *value, int value_size)
+ char *attribute, unsigned int attribute_size, char *value, unsigned int value_size)
{
char *attribute_string;
char *attribute_value_delim;
@@ -50,19 +50,12 @@ int parse_metadata(char *metadata, char **metadata_saveptr,
if ((attribute_value_delim = strchr(attribute_string,
ATTRIBUTE_VALUE_DELIM)) != NULL) {
- bytes_to_copy = MIN((attribute_value_delim - attribute_string),
- attribute_size - 1);
- /* Replace strncpy with strlcpy
- * Add +1 to bytes_to_copy as strlcpy copies size-1 bytes */
- strlcpy(attribute, attribute_string,
- bytes_to_copy+1);
-
- bytes_to_copy = MIN(strlen(attribute_string) - strlen(attribute) - 1,
- value_size - 1);
- /* Replace strncpy with strlcpy
- * Add +1 to bytes_to_copy as strlcpy copies size-1 bytes */
- strlcpy(value, attribute_value_delim + 1,
- bytes_to_copy+1);
+ unsigned int attribute_len = (unsigned int) (attribute_value_delim - attribute_string);
+ /* copy only attribute len + NUL character, or as much as can be fit */
+ bytes_to_copy = MIN(attribute_len + 1, attribute_size);
+
+ strlcpy(attribute, attribute_string, bytes_to_copy);
+ strlcpy(value, attribute_value_delim + 1, value_size);
}
return METADATA_PARSING_CONTINUE;