From 4b366b0f795eb672b4857b044efcb2ddd6b0eab9 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 23 Jun 2012 23:39:31 +0200 Subject: [PATCH] azbox: terminate string in video/proc_get Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/ab2140161abec8e79990e982058ff1f0cdb79317 Author: Stefan Seyfried Date: 2012-06-23 (Sat, 23 Jun 2012) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- azbox/video.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/azbox/video.cpp b/azbox/video.cpp index 4c06166..50da935 100644 --- a/azbox/video.cpp +++ b/azbox/video.cpp @@ -89,8 +89,12 @@ static int proc_get(const char *path, char *value, const int len) return pfd; ret = read(pfd, value, len); value[len-1] = '\0'; /* make sure string is terminated */ - while (ret > 0 && isspace(value[ret-1])) - value[--ret] = '\0'; /* remove trailing whitespace */ + if (ret >= 0) + { + while (ret > 0 && isspace(value[ret-1])) + ret--; /* remove trailing whitespace */ + value[ret] = '\0'; /* terminate, even if ret = 0 */ + } ret2 = close(pfd); if (ret2 < 0) return ret2;