Re: [ModemManager] [PATCH] mm_gsm_parse_scan_response(): Improve regex-construction error handling



And this time with the patch.

    - Nathan

On Wed, Nov 30, 2011 at 2:07 PM, Nathan Williams <njw google com> wrote:
> This was the only code in ModemManager using g_error(), and not
> appropriately, I think.
> The codebase is still mixed on how to handle errors compiling regular
> expressions; other places in this file use g_assert(), while the rest
> of the code tends to report some kind of parse-failure error. Perhaps
> this makes sense in terms of startup versus while-running operations?
>
>    - Nathan
>
From 41c12498c4d3b2c27ccd322e496d7001cfc6047f Mon Sep 17 00:00:00 2001
From: Nathan Williams <njw chromium org>
Date: Wed, 30 Nov 2011 14:02:00 -0500
Subject: [PATCH] mm_gsm_parse_scan_response(): Improve regex-construction error handling

Change the error handling to be a bit more like what appears to have
been intended: if constructing the regex fails, report an error and
return. The existing code looked like it was set up to do this, but
wasn't quite wired together, and had process-terminating calls
(g_error()) followed by other code.

Change-Id: I4a7cee8fe01291976edc2e343fcbeb73e882f20b
---
 src/mm-modem-helpers.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index fe0ba7a..912d9ba 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -112,9 +112,9 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
      *       +COPS: (2,"","T-Mobile","31026",0),(1,"AT&T","AT&T","310410"),0)
      */
 
-    r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, NULL);
+    r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &err);
     if (err) {
-        g_error ("Invalid regular expression: %s", err->message);
+        mm_err ("Invalid regular expression: %s", err->message);
         g_error_free (err);
         g_set_error_literal (error,
                              MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
@@ -141,9 +141,9 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
          *       +COPS: (2,"T - Mobile",,"31026"),(1,"Einstein PCS",,"31064"),(1,"Cingular",,"31041"),,(0,1,3),(0,2)
          */
 
-        r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, NULL);
+        r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, &err);
         if (err) {
-            g_error ("Invalid regular expression: %s", err->message);
+            mm_err ("Invalid regular expression: %s", err->message);
             g_error_free (err);
             g_set_error_literal (error,
                                  MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
-- 
1.7.3.1



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