shithub: libtags

Download patch

ref: 0a1bab10da12e537aab4b7ea9679d7dc54a559c8
parent: 991b8b01d6098bf16b9f490a7f84c4aabf02d3b7
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Tue May 4 10:33:00 EDT 2021

mod: simplify a bit

--- a/mod.c
+++ b/mod.c
@@ -19,28 +19,25 @@
 	"10CH",
 	"16CN",
 	"32CN",
-	nil,
 };
 
 int
 tagmod(Tagctx *ctx)
 {
-	uchar d[20], o[20*2+1];
+	uchar d[20+4], o[20*UTFmax+1];
 	int i;
 
+	if(ctx->read(ctx, d, 20) != 20)
+		return -1;
 	if(ctx->seek(ctx, 1080, 0) != 1080)
 		return -1;
-	if(ctx->read(ctx, d, 4) != 4)
+	if(ctx->read(ctx, d+20, 4) != 4)
 		return -1;
-	for(i = 0; ; i++){
-		if(variants[i] == nil)
-			return -1;
-		if(memcmp(d, variants[i], 4) == 0)
+	for(i = 0; i < nelem(variants); i++){
+		if(memcmp(d+20, variants[i], 4) == 0)
 			break;
 	}
-	if(ctx->seek(ctx, 0, 0) != 0)
-		return -1;
-	if(ctx->read(ctx, d, 20) != 20)
+	if(i >= nelem(variants))
 		return -1;
 	if(iso88591toutf8(o, sizeof(o), d, 20) > 0)
 		txtcb(ctx, Ttitle, "", o);