From 76681c08502cbbe66d0ec572cca6de23bd97a165 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 12 Jul 2016 10:56:31 +0900 Subject: [PATCH] Update code comments --- repmgr.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/repmgr.c b/repmgr.c index 2bec0fbd..4cddc4e7 100644 --- a/repmgr.c +++ b/repmgr.c @@ -5823,7 +5823,9 @@ param_set(const char *param, const char *value) int c; int value_len = strlen(value) + 1; - // scan array for param + /* + * Scan array to see if the parameter is already set - if so replace it + */ for (c = 0; c <= param_count && param_keywords[c] != NULL; c++) { if (strcmp(param_keywords[c], param) == 0) @@ -5831,20 +5833,29 @@ param_set(const char *param, const char *value) if (param_values[c] != NULL) pfree(param_values[c]); - param_values[c] = pg_malloc(value_len); + param_values[c] = pg_malloc0(value_len); strncpy(param_values[c], value, value_len); return; } } + /* + * Parameter not in array - add it and its associated value + */ if (c < param_count) { int param_len = strlen(param) + 1; - param_keywords[c] = pg_malloc(param_len); - param_values[c] = pg_malloc(value_len); + param_keywords[c] = pg_malloc0(param_len); + param_values[c] = pg_malloc0(value_len); strncpy(param_keywords[c], param, param_len); strncpy(param_values[c], value, value_len); } + + /* + * It's theoretically possible a parameter couldn't be added as + * the array is full, but it's highly improbable so we won't + * handle it at the moment. + */ }