| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/mbschr.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||||||||
| 30 | extern int locale_mb_cur_max; | - | ||||||||||||||||||
| 31 | extern int locale_utf8locale; | - | ||||||||||||||||||
| 32 | - | |||||||||||||||||||
| 33 | #undef mbschr | - | ||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | static inline char * | - | ||||||||||||||||||
| 36 | utf8_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:
| 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 | - | |||||||||||||||||||
| 47 | char * | - | ||||||||||||||||||
| 48 | #if defined (PROTOTYPES) | - | ||||||||||||||||||
| 49 | mbschr (const char *s, int c) | - | ||||||||||||||||||
| 50 | #else | - | ||||||||||||||||||
| 51 | mbschr (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)
| 1056788-363901577 | ||||||||||||||||||
| 62 | return (utf8_mbschr (s, c)); /* XXX */ executed 361596937 times by 1 test: return (utf8_mbschr (s, c));Executed by:
| 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)
| 45404-3316024 | ||||||||||||||||||
| 69 | { | - | ||||||||||||||||||
| 70 | pos = (char *)s; | - | ||||||||||||||||||
| 71 | memset (&state, '\0', sizeof(mbstate_t)); | - | ||||||||||||||||||
| 72 | strlength = strlen (s); | - | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | while (strlength > 0)
| 2304640-23046400 | ||||||||||||||||||
| 75 | { | - | ||||||||||||||||||
| 76 | if (is_basic (*pos))
| 2304640-20741760 | ||||||||||||||||||
| 77 | mblength = 1; executed 20741760 times by 1 test: mblength = 1;Executed by:
| 20741760 | ||||||||||||||||||
| 78 | else | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | mblength = mbrlen (pos, strlength, &state); | - | ||||||||||||||||||
| 81 | if (mblength == (size_t)-2 || mblength == (size_t)-1 || mblength == (size_t)0)
| 0-2304640 | ||||||||||||||||||
| 82 | mblength = 1; never executed: mblength = 1; | 0 | ||||||||||||||||||
| 83 | } executed 2304640 times by 1 test: end of blockExecuted by:
| 2304640 | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | if (mblength == 1 && c == (unsigned char)*pos)
| 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 blockExecuted by:
| 23046400 | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | return ((char *)NULL); executed 2304640 times by 1 test: return ((char *) ((void *)0) );Executed by:
| 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:
| 1056788 | ||||||||||||||||||
| 97 | } | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |