shithub: c9

Download patch

ref: a5eae67d27af9422a4460f9e3137a6765ae02012
parent: 833c9d791fffcd83212b222fda04f8568b6cff6c
author: Sigrid <sigrid.haflinadottir@gmail.com>
date: Thu Jan 12 09:04:29 EST 2017

newtag: fix the case where lowfreetag doesn't point to a free tag anymore

--- a/c9.c
+++ b/c9.c
@@ -114,11 +114,15 @@
 
 	for(i = 0; i < (int)sizeof(c->tags)/sizeof(c->tags[0]); i++){
 		uint32_t x, j;
-		for(j = 0, x = c->tags[i]; (x & 1) != 0 && j < C9tagbits; j++);
-		if(j < C9tagbits){
-			c->tags[i] &= ~(1<<j);
-			*tag = i*C9tagbits + j;
-			return 0;
+		if((x = c->tags[i]) == 0)
+			continue;
+		for(j = 0; j < C9tagbits; j++){
+			if((x & (1<<j)) != 0){
+				c->tags[i] &= ~(1<<j);
+				*tag = i*C9tagbits + j;
+				c->lowfreetag = *tag + 1;
+				return 0;
+			}
 		}
 	}
 
--- a/c9.h
+++ b/c9.h
@@ -285,7 +285,7 @@
 	void (*t)(C9ctx *ctx, C9t *t) __attribute__((nonnull(1, 2)));
 
 	/* Callback for error messages. */
-	void (*error)(const char *fmt, ...) __attribute__((nonnull(1)));;
+	void (*error)(const char *fmt, ...) __attribute__((nonnull(1)));
 
 	/* Auxiliary data, can be used by any of above callbacks. */
 	void *aux;