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_rsh(bn_t c, const bn_t a, unsigned int bits) {
	int digits = 0;

	bn_copy(c, a);

	RLC_RIP(bits, digits, bits);

	if (digits > 0) {
		dv_rshd(c->dp, a->dp, a->used, digits);
	}

	if (a->used > digits) {
		c->used = a->used - digits;
	} else {
		c->used = 0;
	}
	c->sign = a->sign;

	if (c->used > 0 && bits > 0) {
		if (digits == 0 && c != a) {
			bn_rshb_low(c->dp, a->dp + digits, a->used - digits, bits);
		} else {
			bn_rshb_low(c->dp, c->dp, c->used, bits);
		}
	}
	bn_trim(c);
}