OpenCoverage

mbschr.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/mbschr.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* mbschr.c - strchr(3) that handles multibyte characters. */-
2-
3/* Copyright (C) 2002 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include <config.h>-
22-
23#ifdef HAVE_STDLIB_H-
24# include <stdlib.h>-
25#endif-
26-
27#include "bashansi.h"-
28#include "shmbutil.h"-
29-
30extern int locale_mb_cur_max;-
31extern int locale_utf8locale;-
32-
33#undef mbschr-
34-
35static inline char *-
36utf8_mbschr (s, c)-
37 const char *s;-
38 int c;-
39{-
40 return strchr (s, c); /* for now */
executed 361596937 times by 1 test: return (__extension__ (__builtin_constant_p ( c ) && !__builtin_constant_p ( s ) && ( c ) == '\0' ? (char *) __rawmemchr ( s , c ) : __builtin_strchr ( s , c ))) ;
Executed by:
  • Self test
361596937
41}-
42-
43/* In some locales, the non-first byte of some multibyte characters have-
44 the same value as some ascii character. Faced with these strings, a-
45 legacy strchr() might return the wrong value. */-
46-
47char *-
48#if defined (PROTOTYPES)-
49mbschr (const char *s, int c)-
50#else-
51mbschr (s, c)-
52 const char *s;-
53 int c;-
54#endif-
55{-
56#if HANDLE_MULTIBYTE-
57 char *pos;-
58 mbstate_t state;-
59 size_t strlength, mblength;-
60-
61 if (locale_utf8locale && c < 0x80)
locale_utf8localeDescription
TRUEevaluated 363901577 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1056788 times by 1 test
Evaluated by:
  • Self test
c < 0x80Description
TRUEevaluated 361596937 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2304640 times by 1 test
Evaluated by:
  • Self test
1056788-363901577
62 return (utf8_mbschr (s, c)); /* XXX */
executed 361596937 times by 1 test: return (utf8_mbschr (s, c));
Executed by:
  • Self test
361596937
63-
64 /* The locale encodings with said weird property are BIG5, BIG5-HKSCS,-
65 GBK, GB18030, SHIFT_JIS, and JOHAB. They exhibit the problem only-
66 when c >= 0x30. We can therefore use the faster bytewise search if-
67 c <= 0x30. */-
68 if ((unsigned char)c >= '0' && locale_mb_cur_max > 1)
(unsigned char)c >= '0'Description
TRUEevaluated 3316024 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45404 times by 1 test
Evaluated by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 2304640 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1011384 times by 1 test
Evaluated by:
  • Self test
45404-3316024
69 {-
70 pos = (char *)s;-
71 memset (&state, '\0', sizeof(mbstate_t));-
72 strlength = strlen (s);-
73-
74 while (strlength > 0)
strlength > 0Description
TRUEevaluated 23046400 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2304640 times by 1 test
Evaluated by:
  • Self test
2304640-23046400
75 {-
76 if (is_basic (*pos))
is_basic (*pos)Description
TRUEevaluated 20741760 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2304640 times by 1 test
Evaluated by:
  • Self test
2304640-20741760
77 mblength = 1;
executed 20741760 times by 1 test: mblength = 1;
Executed by:
  • Self test
20741760
78 else-
79 {-
80 mblength = mbrlen (pos, strlength, &state);-
81 if (mblength == (size_t)-2 || mblength == (size_t)-1 || mblength == (size_t)0)
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 2304640 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 2304640 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)0Description
TRUEnever evaluated
FALSEevaluated 2304640 times by 1 test
Evaluated by:
  • Self test
0-2304640
82 mblength = 1;
never executed: mblength = 1;
0
83 }
executed 2304640 times by 1 test: end of block
Executed by:
  • Self test
2304640
84-
85 if (mblength == 1 && c == (unsigned char)*pos)
mblength == 1Description
TRUEevaluated 23046400 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
c == (unsigned char)*posDescription
TRUEnever evaluated
FALSEevaluated 23046400 times by 1 test
Evaluated by:
  • Self test
0-23046400
86 return pos;
never executed: return pos;
0
87-
88 strlength -= mblength;-
89 pos += mblength;-
90 }
executed 23046400 times by 1 test: end of block
Executed by:
  • Self test
23046400
91-
92 return ((char *)NULL);
executed 2304640 times by 1 test: return ((char *) ((void *)0) );
Executed by:
  • Self test
2304640
93 }-
94 else-
95#endif-
96 return (strchr (s, c));
executed 1056788 times by 1 test: return ( (__extension__ (__builtin_constant_p ( c ) && !__builtin_constant_p ( s ) && ( c ) == '\0' ? (char *) __rawmemchr ( s , c ) : __builtin_strchr ( s , c ))) );
Executed by:
  • Self test
1056788
97}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2