[PATCH gpgme] Fix error handling in _gpgme_parse_status().

Xi Wang xi.wang at gmail.com
Thu Nov 15 09:27:23 CET 2012


The following error handling is broken.

  gpgme_status_code_t r = _gpgme_parse_status(...);
  if (r >= 0) { ... }

Even though _gpgme_parse_status() returns -1 on error, the return type
gpgme_status_code_t is unsigned, and thus (r >= 0) is always true.
This patch changes the return type to int.
---
Another way to fix this problem is to add -1 to enum gpgme_status_code_t.
Then the compiler should consider the enum type as signed.
---
 src/engine-gpg.c   |    2 +-
 src/status-table.c |    2 +-
 src/util.h         |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index 4c7a8b2..5635e91 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -1022,7 +1022,7 @@ read_status (engine_gpg_t gpg)
 		  && buffer[9] >= 'A' && buffer[9] <= 'Z')
 		{
 		  char *rest;
-		  gpgme_status_code_t r;
+		  int r;
 
 		  rest = strchr (buffer + 9, ' ');
 		  if (!rest)
diff --git a/src/status-table.c b/src/status-table.c
index 8060bdb..3434951 100644
--- a/src/status-table.c
+++ b/src/status-table.c
@@ -146,7 +146,7 @@ _gpgme_status_init (void)
 }
 
 
-gpgme_status_code_t
+int
 _gpgme_parse_status (const char *name)
 {
   struct status_table_s t, *r;
diff --git a/src/util.h b/src/util.h
index cf18099..5c2b34f 100644
--- a/src/util.h
+++ b/src/util.h
@@ -140,7 +140,7 @@ gpgme_error_t _gpgme_getenv (const char *name, char **value);
 /*-- status-table.c --*/
 /* Convert a status string to a status code.  */
 void _gpgme_status_init (void);
-gpgme_status_code_t _gpgme_parse_status (const char *name);
+int _gpgme_parse_status (const char *name);
 
 
 #ifdef HAVE_W32_SYSTEM
-- 
1.7.10.4




More information about the Gnupg-devel mailing list