[PATCH 7/7] maint: avoid false-positive NULL-deref warning from clang
Jim Meyering
meyering at redhat.com
Wed Sep 30 09:42:32 UTC 2009
* parted/ui.c: Include <assert.h>.
(command_line_get_disk): Add an assertion that command_line_get_device
currently guarantees will always be true. This placates clang regarding
its sole NULL-deref warning.
(command_line_get_device): Move declarations "down" to first use.
---
parted/ui.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/parted/ui.c b/parted/ui.c
index 295edba..c63df8a 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <unistd.h>
#include <setjmp.h>
+#include <assert.h>
#include "command.h"
#include "strlist.h"
@@ -983,15 +984,12 @@ command_line_get_state (const char* prompt, int* value)
int
command_line_get_device (const char* prompt, PedDevice** value)
{
- char* def_dev_name = *value ? (*value)->path : NULL;
- char* dev_name;
- PedDevice* dev;
-
- dev_name = command_line_get_word (prompt, def_dev_name, NULL, 1);
+ char *def_dev_name = *value ? (*value)->path : NULL;
+ char *dev_name = command_line_get_word (prompt, def_dev_name, NULL, 1);
if (!dev_name)
return 0;
- dev = ped_device_get (dev_name);
+ PedDevice *dev = ped_device_get (dev_name);
free (dev_name);
if (!dev)
return 0;
@@ -1008,6 +1006,7 @@ command_line_get_disk (const char* prompt, PedDisk** value)
if (!command_line_get_device (prompt, &dev))
return 0;
+ assert (*value);
if (dev != (*value)->dev) {
PedDisk* new_disk = ped_disk_new (dev);
if (!new_disk)
--
1.6.5.rc2.177.ga9dd6
More information about the parted-devel
mailing list