math.c 601 B

123456789101112131415161718192021222324
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/common/math.h>
  6. #include <stdarg.h>
  7. AWS_COMMON_API int aws_add_size_checked_varargs(size_t num, size_t *r, ...) {
  8. va_list argp;
  9. va_start(argp, r);
  10. size_t accum = 0;
  11. for (size_t i = 0; i < num; ++i) {
  12. size_t next = va_arg(argp, size_t);
  13. if (aws_add_size_checked(accum, next, &accum) == AWS_OP_ERR) {
  14. va_end(argp);
  15. return AWS_OP_ERR;
  16. }
  17. }
  18. *r = accum;
  19. va_end(argp);
  20. return AWS_OP_SUCCESS;
  21. }