comparison libtommath/bn_mp_init_multi.c @ 1733:d529a52b2f7c coverity coverity

merge coverity from main
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 Jun 2020 21:07:34 +0800
parents 1051e4eea25a
children
comparison
equal deleted inserted replaced
1643:b59623a64678 1733:d529a52b2f7c
1 #include <tommath_private.h> 1 #include "tommath_private.h"
2 #ifdef BN_MP_INIT_MULTI_C 2 #ifdef BN_MP_INIT_MULTI_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 * 4 /* SPDX-License-Identifier: Unlicense */
5 * LibTomMath is a library that provides multiple-precision 5
6 * integer arithmetic as well as number theoretic functionality.
7 *
8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
11 *
12 * The library is free for all purposes without any express
13 * guarantee it works.
14 *
15 * Tom St Denis, [email protected], http://libtom.org
16 */
17 #include <stdarg.h> 6 #include <stdarg.h>
18 7
19 int mp_init_multi(mp_int *mp, ...) 8 mp_err mp_init_multi(mp_int *mp, ...)
20 { 9 {
21 mp_err res = MP_OKAY; /* Assume ok until proven otherwise */ 10 mp_err err = MP_OKAY; /* Assume ok until proven otherwise */
22 int n = 0; /* Number of ok inits */ 11 int n = 0; /* Number of ok inits */
23 mp_int* cur_arg = mp; 12 mp_int *cur_arg = mp;
24 va_list args; 13 va_list args;
25 14
26 va_start(args, mp); /* init args to next argument from caller */ 15 va_start(args, mp); /* init args to next argument from caller */
27 while (cur_arg != NULL) { 16 while (cur_arg != NULL) {
28 if (mp_init(cur_arg) != MP_OKAY) { 17 if (mp_init(cur_arg) != MP_OKAY) {
29 /* Oops - error! Back-track and mp_clear what we already 18 /* Oops - error! Back-track and mp_clear what we already
30 succeeded in init-ing, then return error. 19 succeeded in init-ing, then return error.
31 */ 20 */
32 va_list clean_args; 21 va_list clean_args;
33 22
34 /* now start cleaning up */ 23 /* now start cleaning up */
35 cur_arg = mp; 24 cur_arg = mp;
36 va_start(clean_args, mp); 25 va_start(clean_args, mp);
37 while (n-- != 0) { 26 while (n-- != 0) {
38 mp_clear(cur_arg); 27 mp_clear(cur_arg);
39 cur_arg = va_arg(clean_args, mp_int*); 28 cur_arg = va_arg(clean_args, mp_int *);
40 } 29 }
41 va_end(clean_args); 30 va_end(clean_args);
42 res = MP_MEM; 31 err = MP_MEM;
43 break; 32 break;
44 } 33 }
45 n++; 34 n++;
46 cur_arg = va_arg(args, mp_int*); 35 cur_arg = va_arg(args, mp_int *);
47 } 36 }
48 va_end(args); 37 va_end(args);
49 return res; /* Assumed ok, if error flagged above. */ 38 return err; /* Assumed ok, if error flagged above. */
50 } 39 }
51 40
52 #endif 41 #endif
53
54 /* ref: $Format:%D$ */
55 /* git commit: $Format:%H$ */
56 /* commit time: $Format:%ai$ */