BN_usub: Don't copy when r and a the same
[openssl.git] / crypto / bn / bn_add.c
index e09451d88bba18c7d793a791dfc100e9813b8187..bbb05842452e6558fead3bc84a1cb9cd1482ebbb 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include "bn_lcl.h"
 
 /* r can == a or b */
@@ -222,7 +222,8 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
                 break;
         }
     }
-    memcpy(rp, ap, sizeof(*rp) * (max - i));
+    if (dif && ap != rp)
+        memcpy(rp, ap, sizeof(*rp) * dif);
 
     r->top = max;
     r->neg = 0;