changeset 37117:f996bcd28c23

subreader: Check the %n result variable. 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...
author reimar
date Tue, 27 May 2014 19:22:12 +0000
parents 8e89cf177d51
children 41bc28d9d896
files sub/subreader.c
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sub/subreader.c	Tue May 27 19:22:11 2014 +0000
+++ b/sub/subreader.c	Tue May 27 19:22:12 2014 +0000
@@ -607,44 +607,54 @@
 	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;