smsutil: Fix CR padding logic for 7-bit case
authorDenis Kenzior <denkenz@gmail.com>
Mon, 17 Sep 2012 16:48:03 +0000 (11:48 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Mon, 17 Sep 2012 16:48:03 +0000 (11:48 -0500)
src/smsutil.c

index b4d129f..1e9b471 100644 (file)
@@ -4103,11 +4103,19 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 
                        /*
                         * CR is a padding character, which means we can
-                        * safely discard everything afterwards
+                        * safely discard everything afterwards if there are
+                        * only trailing CR characters.
                         */
                        for (; i < written; i++, bufsize++) {
-                               if (unpacked[i] == '\r')
-                                       break;
+                               if (unpacked[i] == '\r') {
+                                       unsigned int t;
+
+                                       t = strspn((const char *) unpacked + i,
+                                                       "\r");
+
+                                       if (t + i == written)
+                                               break;
+                               }
 
                                buf[bufsize] = unpacked[i];
                        }