Fix ser_number for no remaining val byte.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/cgminer.c b/cgminer.c
index 338f427..557f577 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2286,13 +2286,9 @@ static bool gbt_solo_decode(struct pool *pool, json_t *res_val)
memset(pool->scriptsig_base, 0, 42);
pool->scriptsig_base[ofs++] = 49; // Template is 49 bytes
- /* Put block height at start of template. Pad to 9 == size of int64_t */
- len = ser_number(pool->scriptsig_base + ofs, height);
- ofs += len;
- len = 9 - len - 1;
- if (len)
- pool->scriptsig_base[ofs++] = len;
- ofs += len;
+ /* Put block height at start of template. */
+ ser_number(pool->scriptsig_base + ofs, height);
+ ofs += 9;
/* Followed by flags */
pool->scriptsig_base[ofs++] = 7; // Flags length should be 7
diff --git a/util.c b/util.c
index 27cd8f8..0f1bb76 100644
--- a/util.c
+++ b/util.c
@@ -719,19 +719,23 @@ void address_to_pubkeyhash(unsigned char *pkh, const char *addr)
pkh[24] = 0xac;
}
-/* For encoding nHeight into coinbase */
-int ser_number(unsigned char *s, int64_t val)
-{
- int i = 1;
-
- s[0] = i;
- while (val > 127) {
- s[i] = val % 256;
- s[0] = ++i;
- val /= 256;
- }
- s[++i] = val;
- return i;
+/* For encoding nHeight into coinbase, pad out to 9 bytes */
+void ser_number(unsigned char *s, int64_t val)
+{
+ int64_t *i64 = (int64_t *)&s[1];
+ int len;
+
+ if (val < 128)
+ len = 1;
+ else if (val < 16512)
+ len = 2;
+ else if (val < 2113664)
+ len = 3;
+ else
+ len = 4;
+ *i64 = htole64(val);
+ s[0] = len++;
+ s[len] = 9 - len;
}
/* For encoding variable length strings */
diff --git a/util.h b/util.h
index 9b5d334..6df1ee9 100644
--- a/util.h
+++ b/util.h
@@ -108,7 +108,7 @@ enum dev_reason;
struct cgpu_info;
void b58tobin(unsigned char *b58bin, const char *b58);
void address_to_pubkeyhash(unsigned char *pkh, const char *addr);
-int ser_number(unsigned char *s, int64_t val);
+void ser_number(unsigned char *s, int64_t val);
unsigned char *ser_string(char *s, int *slen);
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
void thr_info_cancel(struct thr_info *thr);