1/*
2 * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16#include <aws/common/math.h>
17#include <stdarg.h>
18
19AWS_COMMON_API int aws_add_size_checked_varargs(size_t num, size_t *r, ...) {
20 va_list argp;
21 va_start(argp, r);
22
23 size_t accum = 0;
24 for (size_t i = 0; i < num; ++i) {
25 size_t next = va_arg(argp, size_t);
26 if (aws_add_size_checked(accum, next, &accum) == AWS_OP_ERR) {
27 va_end(argp);
28 return AWS_OP_ERR;
29 }
30 }
31 *r = accum;
32 va_end(argp);
33 return AWS_OP_SUCCESS;
34}
35