LCOV - code coverage report
Current view: top level - aws-c-common/include/aws/common - string.inl (source / functions) Hit Total Coverage
Test: all_fuzz.info Lines: 15 22 68.2 %
Date: 2021-04-23 16:28:21 Functions: 27 190 14.2 %

          Line data    Source code
       1             : #ifndef AWS_COMMON_STRING_INL
       2             : #define AWS_COMMON_STRING_INL
       3             : /**
       4             :  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       5             :  * SPDX-License-Identifier: Apache-2.0.
       6             :  */
       7             : #include <aws/common/string.h>
       8             : #include <ctype.h>
       9             : 
      10             : AWS_EXTERN_C_BEGIN
      11             : /**
      12             :  * Equivalent to str->bytes.
      13             :  */
      14             : AWS_STATIC_IMPL
      15      564425 : const uint8_t *aws_string_bytes(const struct aws_string *str) {
      16      564425 :     AWS_PRECONDITION(aws_string_is_valid(str));
      17      564425 :     return str->bytes;
      18      564425 : }
      19             : 
      20             : /**
      21             :  * Equivalent to `(const char *)str->bytes`.
      22             :  */
      23             : AWS_STATIC_IMPL
      24           0 : const char *aws_string_c_str(const struct aws_string *str) {
      25           0 :     AWS_PRECONDITION(aws_string_is_valid(str));
      26           0 :     return (const char *)str->bytes;
      27           0 : }
      28             : 
      29             : /**
      30             :  * Evaluates the set of properties that define the shape of all valid aws_string structures.
      31             :  * It is also a cheap check, in the sense it run in constant time (i.e., no loops or recursion).
      32             :  */
      33             : AWS_STATIC_IMPL
      34     4850809 : bool aws_string_is_valid(const struct aws_string *str) {
      35     4850809 :     return str && AWS_MEM_IS_READABLE(&str->bytes[0], str->len + 1) && str->bytes[str->len] == 0;
      36     4850809 : }
      37             : 
      38             : /**
      39             :  * Best-effort checks aws_string invariants, when the str->len is unknown
      40             :  */
      41             : AWS_STATIC_IMPL
      42      947649 : bool aws_c_string_is_valid(const char *str) {
      43      947649 :     /* Knowing the actual length to check would require strlen(), which is
      44      947649 :      * a) linear time in the length of the string
      45      947649 :      * b) could already cause a memory violation for a non-zero-terminated string.
      46      947649 :      * But we know that a c-string must have at least one character, to store the null terminator
      47      947649 :      */
      48      947649 :     return str && AWS_MEM_IS_READABLE(str, 1);
      49      947649 : }
      50             : 
      51             : /**
      52             :  * Evaluates if a char is a white character.
      53             :  */
      54             : AWS_STATIC_IMPL
      55           0 : bool aws_char_is_space(uint8_t c) {
      56           0 :     return aws_isspace(c);
      57           0 : }
      58             : 
      59             : AWS_EXTERN_C_END
      60             : #endif /* AWS_COMMON_STRING_INL */

Generated by: LCOV version 1.13