[MPlayer-dev-eng] [PATCH 2/2] subreader: Check the %n result variable.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat May 24 20:04:31 CEST 2014


This ensures we had an actual match against the
full string.
Ideally this would be possible by checking for a one larger
return value, but unfortunately the standard is unclear if
%n arguments should be counted or not...
---
 sub/subreader.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sub/subreader.c b/sub/subreader.c
index 3c42552..7f7771c 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -605,44 +605,54 @@ static subtitle *sub_read_line_rt(stream_t *st,subtitle *current, int utf16) {
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b3,&b4,&plen) >= 4;
+		match &= plen > 0;
 	}
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b2,&b3,&b4,&plen) >= 5;
+		match &= plen > 0;
 	}
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&plen) >= 4;
+		match &= plen > 0;
 	}
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&b4,&plen) >= 5;
+		match &= plen > 0;
 	}
 //	sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen) >= 5
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&b4,&plen) >= 6;
+		match &= plen > 0;
 	}
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen) >= 8;
+		match &= plen > 0;
 	}
 	//now try it without end time
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&plen) >= 2;
+		match &= plen > 0;
 	}
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&plen) >= 2;
+		match &= plen > 0;
 	}
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&plen) >= 3;
+		match &= plen > 0;
 	}
 	if (!match) {
 		plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 		match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&plen) >= 4;
+		match &= plen > 0;
 	}
 	if (!match)
 	    continue;
-- 
2.0.0.rc4



More information about the MPlayer-dev-eng mailing list