aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-common/source/math.c
blob: 40d833c1a946a87c1d418016dba2434d2fc9bfd2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/common/math.h>
#include <stdarg.h>

AWS_COMMON_API int aws_add_size_checked_varargs(size_t num, size_t *r, ...) {
    va_list argp;
    va_start(argp, r);

    size_t accum = 0;
    for (size_t i = 0; i < num; ++i) {
        size_t next = va_arg(argp, size_t);
        if (aws_add_size_checked(accum, next, &accum) == AWS_OP_ERR) {
            va_end(argp);
            return AWS_OP_ERR;
        }
    }
    *r = accum;
    va_end(argp);
    return AWS_OP_SUCCESS;
}