Ticket #7062: libs_libmyth-pointer-checks

File libs_libmyth-pointer-checks, 1.5 KB (added by Erik Hovland <erik@…>, 10 years ago)

Checks the pointers given by system calls.

Line 
1Make sure that functions that return null are checked.
2
3From: Erik Hovland <erik@hovland.org>
4
5
6---
7
8 mythtv/libs/libmyth/mediamonitor-unix.cpp |    5 ++++-
9 mythtv/libs/libmyth/util.cpp              |    3 +--
10 2 files changed, 5 insertions(+), 3 deletions(-)
11
12
13diff --git a/mythtv/libs/libmyth/mediamonitor-unix.cpp b/mythtv/libs/libmyth/mediamonitor-unix.cpp
14index 43fc666..5f053e4 100644
15--- a/mythtv/libs/libmyth/mediamonitor-unix.cpp
16+++ b/mythtv/libs/libmyth/mediamonitor-unix.cpp
17@@ -480,9 +480,12 @@ bool MediaMonitorUnix::AddDevice(struct fstab * mep)
18     }
19     else
20     {
21-        char *dev;
22+        char *dev = 0;
23         int len = 0;
24         dev = strstr(mep->fs_mntops, SUPER_OPT_DEV);
25+        if (dev == NULL)
26+            return false;
27+
28         dev += sizeof(SUPER_OPT_DEV)-1;
29         while (dev[len] != ',' && dev[len] != ' ' && dev[len] != 0)
30             len++;
31diff --git a/mythtv/libs/libmyth/util.cpp b/mythtv/libs/libmyth/util.cpp
32index 6167227..e579db5 100644
33--- a/mythtv/libs/libmyth/util.cpp
34+++ b/mythtv/libs/libmyth/util.cpp
35@@ -304,10 +304,9 @@ static QString getSystemTimeZoneID(void)
36             struct tm *result = (struct tm *)malloc(sizeof(*result));
37 
38             t = time(NULL);
39-            localtime_r(&t, result);
40-
41             if (result != NULL)
42             {
43+                localtime_r(&t, result);
44                 if (strftime(name, sizeof(name), "%Z", result) > 0)
45                     zone_id = name;
46                 free(result);