All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] smsutil: <CR> is not necessarily a padding character in CBS message
@ 2012-07-27 15:08 Philippe Nunes
  2012-07-27  6:02 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Nunes @ 2012-07-27 15:08 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1766 bytes --]

---
 src/smsutil.c |   37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/src/smsutil.c b/src/smsutil.c
index a541964..59eb7b1 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -4090,7 +4090,7 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 			unsigned char unpacked[CBS_MAX_GSM_CHARS];
 			long written;
 			int max_chars;
-			int i;
+			int i, j;
 
 			max_chars =
 				sms_text_capacity_gsm(CBS_MAX_GSM_CHARS, taken);
@@ -4102,12 +4102,24 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 			i = iso639 ? 3 : 0;
 
 			/*
-			 * CR is a padding character, which means we can
-			 * safely discard everything afterwards
+			 * CR can be used as a padding character, which means
+			 * we can safely discard everything afterwards
 			 */
+
 			for (; i < written; i++, bufsize++) {
-				if (unpacked[i] == '\r')
-					break;
+				if (unpacked[i] == '\r') {
+					/*
+					 * check if this is a padding character or 
+					 * if it is a wanted <CR>
+					 */
+					for (j=i+1; j < written; j++)
+						if (unpacked[j] != '\r')
+							break;
+
+					if (j == written)
+						break;
+				}
+
 
 				buf[bufsize] = unpacked[i];
 			}
@@ -4135,8 +4147,19 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 			}
 
 			while (i < max_offset) {
-				if (ud[i] == 0x00 && ud[i+1] == '\r')
-					break;
+				if (ud[i] == 0x00 && ud[i+1] == '\r') {
+					int j = i+2;
+
+					while (j < max_offset) {
+						if (ud[j] != 0x00 || ud[j+1] != '\r')
+							break;
+
+						j += 2;
+					}
+
+					if (j == max_offset)
+						break;
+				}
 
 				buf[bufsize] = ud[i];
 				buf[bufsize + 1] = ud[i+1];
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-27 15:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-27 15:08 [PATCH] smsutil: <CR> is not necessarily a padding character in CBS message Philippe Nunes
2012-07-27  6:02 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.