Use strncpy() with a carefully chosen length rather than snprintf() into a carefully undersized buffer. This should be mildly faster (no need to process the "%s", and no need to walk the entire source string to calculate the return value), but the primary reason for the switch is to improve readability: snprintf() is almost always used on a buffer that is expected to be big enough to hold the entire formatted string, so purposeful truncation with snprintf() is highly unusual. --- lib/configlib/config_load.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/configlib/config_load.c b/lib/configlib/config_load.c index 7ba9258..6aa2be3 100644 --- a/lib/configlib/config_load.c +++ b/lib/configlib/config_load.c @@ -298,9 +298,9 @@ static bool get_value( ret = false; goto done; } + variable[variable_size] = 0; - snprintf(variable, variable_size + 1, "%s", - line + *line_offset + 2); + strncpy(variable, line + *line_offset + 2, variable_size); variable_value = getenv(variable); if (variable_value == NULL) -- 2.4.5 ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ rpstir-devel mailing list rpstir-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpstir-devel