LCOV - code coverage report
Current view: top level - aws-c-common/include/aws/common - zero.inl (source / functions) Hit Total Coverage
Test: all_fuzz.info Lines: 23 27 85.2 %
Date: 2021-04-23 16:28:21 Functions: 2 178 1.1 %

          Line data    Source code
       1             : #ifndef AWS_COMMON_ZERO_INL
       2             : #define AWS_COMMON_ZERO_INL
       3             : 
       4             : /**
       5             :  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       6             :  * SPDX-License-Identifier: Apache-2.0.
       7             :  */
       8             : 
       9             : #include <aws/common/stdbool.h>
      10             : #include <aws/common/stdint.h>
      11             : #include <aws/common/zero.h>
      12             : #include <string.h>
      13             : 
      14             : AWS_EXTERN_C_BEGIN
      15             : /**
      16             :  * Returns whether each byte is zero.
      17             :  */
      18             : AWS_STATIC_IMPL
      19      381271 : bool aws_is_mem_zeroed(const void *buf, size_t bufsize) {
      20      381271 :     /* Optimization idea: vectorized instructions to check more than 64 bits at a time. */
      21      381271 : 
      22      381271 :     /* Check 64 bits at a time */
      23      381271 :     const uint64_t *buf_u64 = (const uint64_t *)buf;
      24      381271 :     const size_t num_u64_checks = bufsize / 8;
      25      381271 :     size_t i;
      26     1202126 :     for (i = 0; i < num_u64_checks; ++i) {
      27     1037955 :         if (buf_u64[i]) {
      28      217100 :             return false;
      29      217100 :         }
      30     1037955 :     }
      31      381271 : 
      32      381271 :     /* Update buf to where u64 checks left off */
      33      381271 :     buf = buf_u64 + num_u64_checks;
      34      164171 :     bufsize = bufsize % 8;
      35      164171 : 
      36      164171 :     /* Check 8 bits at a time */
      37      164171 :     const uint8_t *buf_u8 = (const uint8_t *)buf;
      38      164171 :     for (i = 0; i < bufsize; ++i) {
      39           0 :         if (buf_u8[i]) {
      40           0 :             return false;
      41           0 :         }
      42           0 :     }
      43      164171 : 
      44      164171 :     return true;
      45      164171 : }
      46             : 
      47             : AWS_EXTERN_C_END
      48             : 
      49             : #endif /* AWS_COMMON_ZERO_INL */

Generated by: LCOV version 1.13