Closed sipa closed 7 years ago
I am in ur code optimizing ur statements
index e5b26ec..2dc56aa 100644 --- a/ref/c/segwit_addr.c +++ b/ref/c/segwit_addr.c @@ -52,11 +52,11 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat size_t i = 0; while (hrp[i] != 0) { if (hrp[i] >= 'A' && hrp[i] <= 'Z') return 0; - if (!(hrp[i] >> 5)) return 0; +/* if (!(hrp[i] >> 5)) return 0;*/ chk = bech32_polymod_step(chk) ^ (hrp[i] >> 5); ++i; } - if (i + 7 + data_len > 90) return 0; +/* if (i + 7 + data_len > 90) return 0;*/ chk = bech32_polymod_step(chk); while (*hrp != 0) { chk = bech32_polymod_step(chk) ^ (*hrp & 0x1f); @@ -64,7 +64,7 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat } *(output++) = '1'; for (i = 0; i < data_len; ++i) { - if (*data >> 5) return 0; +/* if (*data >> 5) return 0;*/ chk = bech32_polymod_step(chk) ^ (*data); *(output++) = charset[*(data++)]; } @@ -93,7 +93,7 @@ int bech32_decode(char* hrp, uint8_t *data, size_t *data_len, const char *input) ++(*data_len); } hrp_len = input_len - (1 + *data_len); - if (hrp_len < 1 || *data_len < 6) { + if (hrp_len < 1 /*|| *data_len < 6*/) { return 0; } *(data_len) -= 6; @@ -118,7 +118,7 @@ int bech32_decode(char* hrp, uint8_t *data, size_t *data_len, const char *input) } ++i; while (i < input_len) { - int v = (input[i] & 0x80) ? -1 : charset_rev[(int)input[i]]; + int v = charset_rev[(int)input[i]]; /*(input[i] & 0x80) ? -1 : charset_rev[(int)input[i]];*/ if (input[i] >= 'a' && input[i] <= 'z') have_lower = 1; if (input[i] >= 'A' && input[i] <= 'Z') have_upper = 1; if (v == -1) { @@ -152,7 +152,7 @@ static int convert_bits(uint8_t* out, size_t* outlen, int outbits, const uint8_t if (bits) { out[(*outlen)++] = (val << (outbits - bits)) & maxv; } - } else if (((val << (outbits - bits)) & maxv) || bits >= inbits) { + } else if (((val << (outbits - bits)) & maxv) /*|| bits >= inbits*/) { return 0; } return 1;
bits >= inbits padding branch still untested.
Fixed.
ACK
I am in ur code optimizing ur statements