From 746c4b6b7ccf67c64698f8b75dfca05abb31b4f3 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Tue, 19 May 2015 22:30:44 -0500 Subject: [PATCH] wmgeneral: Check if malloc fails. Fixes "(error) Uninitialized variable: ret" found by cppcheck. --- wmckgmail/wmgeneral/misc.c | 5 +++++ wmcpufreq/wmgeneral/misc.c | 5 +++++ wmifs/wmgeneral/misc.c | 5 +++++ wmitime/wmgeneral/misc.c | 5 +++++ wmkeys/wmgeneral/misc.c | 5 +++++ wmmon/wmgeneral/misc.c | 5 +++++ wmppp.app/wmgeneral/misc.c | 5 +++++ wmsm.app/wmgeneral/misc.c | 5 +++++ wmtime/wmgeneral/misc.c | 7 ++++++- wmtz/wmgeneral/misc.c | 5 +++++ 10 files changed, 51 insertions(+), 1 deletion(-) mode change 100755 => 100644 wmcpufreq/wmgeneral/misc.c diff --git a/wmckgmail/wmgeneral/misc.c b/wmckgmail/wmgeneral/misc.c index 1f3bb2e..cdaf7e0 100644 --- a/wmckgmail/wmgeneral/misc.c +++ b/wmckgmail/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmcpufreq/wmgeneral/misc.c b/wmcpufreq/wmgeneral/misc.c old mode 100755 new mode 100644 index 34281e2..ba3885b --- a/wmcpufreq/wmgeneral/misc.c +++ b/wmcpufreq/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmifs/wmgeneral/misc.c b/wmifs/wmgeneral/misc.c index 950d7ac..243f1bc 100644 --- a/wmifs/wmgeneral/misc.c +++ b/wmifs/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmitime/wmgeneral/misc.c b/wmitime/wmgeneral/misc.c index 1f3bb2e..cdaf7e0 100644 --- a/wmitime/wmgeneral/misc.c +++ b/wmitime/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmkeys/wmgeneral/misc.c b/wmkeys/wmgeneral/misc.c index 1f3bb2e..cdaf7e0 100644 --- a/wmkeys/wmgeneral/misc.c +++ b/wmkeys/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmmon/wmgeneral/misc.c b/wmmon/wmgeneral/misc.c index 1f3bb2e..cdaf7e0 100644 --- a/wmmon/wmgeneral/misc.c +++ b/wmmon/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmppp.app/wmgeneral/misc.c b/wmppp.app/wmgeneral/misc.c index 1f3bb2e..cdaf7e0 100644 --- a/wmppp.app/wmgeneral/misc.c +++ b/wmppp.app/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmsm.app/wmgeneral/misc.c b/wmsm.app/wmgeneral/misc.c index 1f3bb2e..cdaf7e0 100644 --- a/wmsm.app/wmgeneral/misc.c +++ b/wmsm.app/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmtime/wmgeneral/misc.c b/wmtime/wmgeneral/misc.c index c36cdb4..cdaf7e0 100644 --- a/wmtime/wmgeneral/misc.c +++ b/wmtime/wmgeneral/misc.c @@ -16,11 +16,12 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0; diff --git a/wmtz/wmgeneral/misc.c b/wmtz/wmgeneral/misc.c index 1f3bb2e..cdaf7e0 100644 --- a/wmtz/wmgeneral/misc.c +++ b/wmtz/wmgeneral/misc.c @@ -21,6 +21,7 @@ #include #include +#include #include "list.h" #include "misc.h" @@ -63,6 +64,10 @@ next_token(char *word, char **next) int state, ctype; t = ret = malloc(strlen(word)+1); + if (ret == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + exit(EXIT_FAILURE); + } ptr = word; state = 0;