bug-patch
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-patch] [PATCH] remove side effect from assert


From: Jim Meyering
Subject: [bug-patch] [PATCH] remove side effect from assert
Date: Tue, 24 May 2011 15:42:49 +0200

While looking at the nearby expression (suspicious-but-ok,
highlighted by coverity as matching the form malloc(strlen(...)),

  u = v = xmalloc (strlen (s));

I saw that the preceding assert statement had a side effect:

    assert (*s++ == '"');

That means disabling assertions would have impacted correctness.
Here's the fix:

>From 508b50df8241456ab0a3a4829d3501cddf1167b9 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 24 May 2011 15:35:50 +0200
Subject: [PATCH] remove side effect from assert

* src/util.c (parse_c_string): Don't increment "s" in assert.
---
 src/util.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/util.c b/src/util.c
index 85dd803..8b23a3b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1319,7 +1319,8 @@ parse_c_string (char const *s, char const **endp)
 {
   char *u, *v;

-  assert (*s++ == '"');
+  assert (*s == '"');
+  s++;
   u = v = xmalloc (strlen (s));
   for (;;)
     {
--
1.7.5.2.585.gfbd48



reply via email to

[Prev in Thread] Current Thread [Next in Thread]