LCOV - code coverage report
Current view: top level - lib/libc/minimal/source/stdlib - atoi.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 16 0.0 %
Date: 2022-08-18 11:36:24 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 9 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: MIT */
       2                 :            : 
       3                 :            : /*
       4                 :            :  * Copyright © 2005-2014 Rich Felker, et al.
       5                 :            :  *
       6                 :            :  * Permission is hereby granted, free of charge, to any person obtaining
       7                 :            :  * a copy of this software and associated documentation files (the
       8                 :            :  * "Software"), to deal in the Software without restriction, including
       9                 :            :  * without limitation the rights to use, copy, modify, merge, publish,
      10                 :            :  * distribute, sublicense, and/or sell copies of the Software, and to
      11                 :            :  * permit persons to whom the Software is furnished to do so, subject to
      12                 :            :  * the following conditions:
      13                 :            :  *
      14                 :            :  * The above copyright notice and this permission notice shall be
      15                 :            :  * included in all copies or substantial portions of the Software.
      16                 :            :  *
      17                 :            :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      18                 :            :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      19                 :            :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      20                 :            :  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      21                 :            :  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      22                 :            :  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      23                 :            :  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      24                 :            :  */
      25                 :            : 
      26                 :            : /* From: http://fossies.org/dox/musl-1.0.5/atoi_8c_source.html */
      27                 :            : 
      28                 :            : #include <stdlib.h>
      29                 :            : #include <ctype.h>
      30                 :            : 
      31                 :            : int atoi(const char *s)
      32                 :            : {
      33                 :          0 :         int n = 0;
      34                 :          0 :         int neg = 0;
      35                 :            : 
      36         [ #  # ]:          0 :         while (isspace(*s)) {
      37                 :          0 :                 s++;
      38                 :            :         }
      39      [ #  #  # ]:          0 :         switch (*s) {
      40                 :          0 :         case '-':
      41                 :          0 :                 neg = 1;
      42                 :          0 :                 s++;
      43                 :          0 :                 break;  /* artifact to quiet coverity warning */
      44                 :          0 :         case '+':
      45                 :          0 :                 s++;
      46                 :          0 :         default:
      47                 :            :                 /* Add an empty default with break, this is a defensive programming.
      48                 :            :                  * Static analysis tool won't raise a violation if default is empty,
      49                 :            :                  * but has that comment.
      50                 :            :                  */
      51                 :          0 :                 break;
      52                 :            :         }
      53                 :            :         /* Compute n as a negative number to avoid overflow on INT_MIN */
      54         [ #  # ]:          0 :         while (isdigit(*s)) {
      55                 :          0 :                 n = 10*n - (*s++ - '0');
      56                 :            :         }
      57         [ #  # ]:          0 :         return neg ? n : -n;
      58                 :            : }

Generated by: LCOV version 1.14