Language: C
Label: safe
CWE: CWE-190 \u2014 Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.

Code:
void bn_lsh(bn_t c, const bn_t a, unsigned int bits) {
	int digits;
	dig_t carry;

	bn_copy(c, a);

	RLC_RIP(bits, digits, bits);

	RLC_TRY {
		bn_grow(c, c->used + digits + (bits > 0));

		c->used = a->used + digits;
		c->sign = a->sign;
		if (digits > 0) {
			dv_lshd(c->dp, a->dp, c->used, digits);
		}

		if (bits > 0) {
			if (c != a) {
				carry = bn_lshb_low(c->dp + digits, a->dp, a->used, bits);
			} else {
				carry = bn_lshb_low(c->dp + digits, c->dp + digits, c->used - digits, bits);
			}
			if (carry != 0) {
				c->dp[c->used] = carry;
				(c->used)++;
			}
		}
		bn_trim(c);
	} RLC_CATCH_ANY {
		RLC_THROW(ERR_CAUGHT);
	}
}