# HG changeset patch
# User reimar
# Date 1401218532 0
# Node ID f996bcd28c233bbbc2bea7ef1b25754371e54588
# Parent 8e89cf177d51d2bdd2cf0fbff524086a23763a2b
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...
diff -r 8e89cf177d51 -r f996bcd28c23 sub/subreader.c
--- 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\"%*[^<]%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\"%*[^<]%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\"%*[^<]%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\"%*[^<]%n",&a2,&a3,&b2,&b3,&b4,&plen) >= 5;
+ match &= plen > 0;
}
// sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]%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\"%*[^<]%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\"%*[^<]%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\"%*[^<]%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\"%*[^<]%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\"%*[^<]%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\"%*[^<]%n",&a1,&a2,&a3,&a4,&plen) >= 4;
+ match &= plen > 0;
}
if (!match)
continue;