/src/htslib/htslib/kstring.h
Line | Count | Source |
1 | | /* The MIT License |
2 | | |
3 | | Copyright (C) 2011 by Attractive Chaos <attractor@live.co.uk> |
4 | | Copyright (C) 2013-2014, 2016, 2018-2020, 2022, 2024-2025 Genome Research Ltd. |
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 |
20 | | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
21 | | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
22 | | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
23 | | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
24 | | SOFTWARE. |
25 | | */ |
26 | | |
27 | | #ifndef KSTRING_H |
28 | | #define KSTRING_H |
29 | | |
30 | | #include <stdlib.h> |
31 | | #include <string.h> |
32 | | #include <stdarg.h> |
33 | | #include <stdint.h> |
34 | | #include <stdio.h> |
35 | | #include <limits.h> |
36 | | #include <errno.h> |
37 | | #include <sys/types.h> |
38 | | |
39 | | #include "hts_defs.h" |
40 | | #include "kroundup.h" |
41 | | |
42 | | #if defined __GNUC__ && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)) |
43 | | #ifdef __MINGW_PRINTF_FORMAT |
44 | | #define KS_ATTR_PRINTF(fmt, arg) __attribute__((__format__ (__MINGW_PRINTF_FORMAT, fmt, arg))) |
45 | | #else |
46 | | #define KS_ATTR_PRINTF(fmt, arg) __attribute__((__format__ (__printf__, fmt, arg))) |
47 | | #endif // __MINGW_PRINTF_FORMAT |
48 | | #else |
49 | | #define KS_ATTR_PRINTF(fmt, arg) |
50 | | #endif |
51 | | |
52 | | #ifndef HAVE___BUILTIN_CLZ |
53 | | #if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) |
54 | | #define HAVE___BUILTIN_CLZ 1 |
55 | | #endif |
56 | | #endif |
57 | | |
58 | | // Ensure ssize_t exists within this header. All #includes must precede this, |
59 | | // and ssize_t must be undefined again at the end of this header. |
60 | | #if defined _MSC_VER && defined _INTPTR_T_DEFINED && !defined _SSIZE_T_DEFINED && !defined ssize_t |
61 | | #define HTSLIB_SSIZE_T |
62 | | #define ssize_t intptr_t |
63 | | #endif |
64 | | |
65 | | #ifndef EOVERFLOW |
66 | | #define HTSLIB_EOVERFLOW |
67 | | #define EOVERFLOW ERANGE |
68 | | #endif |
69 | | |
70 | | /* kstring_t is a simple non-opaque type whose fields are likely to be |
71 | | * used directly by user code (but see also ks_str() and ks_len() below). |
72 | | * A kstring_t object is initialised by either of |
73 | | * kstring_t str = KS_INITIALIZE; |
74 | | * kstring_t str; ...; ks_initialize(&str); |
75 | | * and either ownership of the underlying buffer should be given away before |
76 | | * the object disappears (see ks_release() below) or the kstring_t should be |
77 | | * destroyed with ks_free(&str) or free(str.s) */ |
78 | | #ifndef KSTRING_T |
79 | | #define KSTRING_T kstring_t |
80 | | typedef struct kstring_t { |
81 | | size_t l, m; |
82 | | char *s; |
83 | | } kstring_t; |
84 | | #endif |
85 | | |
86 | | typedef struct ks_tokaux_t { |
87 | | uint64_t tab[4]; |
88 | | int sep, finished; |
89 | | const char *p; // end of the current token |
90 | | } ks_tokaux_t; |
91 | | |
92 | | #ifdef __cplusplus |
93 | | extern "C" { |
94 | | #endif |
95 | | |
96 | | HTSLIB_EXPORT |
97 | | int kvsprintf(kstring_t *s, const char *fmt, va_list ap) KS_ATTR_PRINTF(2,0); |
98 | | |
99 | | HTSLIB_EXPORT |
100 | | int ksprintf(kstring_t *s, const char *fmt, ...) KS_ATTR_PRINTF(2,3); |
101 | | |
102 | | HTSLIB_EXPORT |
103 | | int kputd(double d, kstring_t *s); // custom %g only handler |
104 | | |
105 | | HTSLIB_EXPORT |
106 | | int ksplit_core(char *s, int delimiter, int *_max, int **_offsets); |
107 | | |
108 | | HTSLIB_EXPORT |
109 | | char *kstrstr(const char *str, const char *pat, int **prep); |
110 | | |
111 | | HTSLIB_EXPORT |
112 | | char *kstrnstr(const char *str, const char *pat, int n, int **prep); |
113 | | |
114 | | HTSLIB_EXPORT |
115 | | void *kmemmem(const void *str, int n, const void *pat, int m, int **prep); |
116 | | |
117 | | /* kstrtok() is similar to strtok_r() except that str is not |
118 | | * modified and both str and sep can be NULL. For efficiency, it is |
119 | | * actually recommended to set both to NULL in the subsequent calls |
120 | | * if sep is not changed. */ |
121 | | HTSLIB_EXPORT |
122 | | char *kstrtok(const char *str, const char *sep, ks_tokaux_t *aux); |
123 | | |
124 | | /* kgetline() uses the supplied fgets()-like function to read a "\n"- |
125 | | * or "\r\n"-terminated line from fp. The line read is appended to the |
126 | | * kstring without its terminator and 0 is returned; EOF is returned at |
127 | | * EOF or on error (determined by querying fp, as per fgets()). */ |
128 | | typedef char *kgets_func(char *, int, void *); |
129 | | HTSLIB_EXPORT |
130 | | int kgetline(kstring_t *s, kgets_func *fgets_fn, void *fp); |
131 | | |
132 | | /* Convenience function to call kgetline with a FILE * */ |
133 | | HTSLIB_EXPORT |
134 | | int kfgetline(kstring_t *s, FILE *fp); |
135 | | |
136 | | /* kgetline2() uses the supplied hgetln()-like function to read a "\n"- |
137 | | * or "\r\n"-terminated line from fp. The line read is appended to the |
138 | | * ksring without its terminator and 0 is returned; EOF is returned at |
139 | | * EOF or on error (determined by querying fp, as per fgets()). */ |
140 | | typedef ssize_t kgets_func2(char *, size_t, void *); |
141 | | HTSLIB_EXPORT |
142 | | int kgetline2(kstring_t *s, kgets_func2 *fgets_fn, void *fp); |
143 | | |
144 | | #ifdef __cplusplus |
145 | | } |
146 | | #endif |
147 | | |
148 | | /// kstring initializer for structure assignment |
149 | 5.42k | #define KS_INITIALIZE { 0, 0, NULL } |
150 | | |
151 | | /// kstring initializer for pointers |
152 | | /** |
153 | | @note Not to be used if the buffer has been allocated. Use ks_release() |
154 | | or ks_clear() instead. |
155 | | */ |
156 | | |
157 | | static inline void ks_initialize(kstring_t *s) |
158 | 23.3k | { |
159 | 23.3k | s->l = s->m = 0; |
160 | 23.3k | s->s = NULL; |
161 | 23.3k | } Unexecuted instantiation: hts_open_fuzzer.c:ks_initialize Line | Count | Source | 158 | 1.05k | { | 159 | 1.05k | s->l = s->m = 0; | 160 | | s->s = NULL; | 161 | 1.05k | } |
Unexecuted instantiation: hfile.c:ks_initialize Unexecuted instantiation: hts.c:ks_initialize Unexecuted instantiation: hts_expr.c:ks_initialize Unexecuted instantiation: multipart.c:ks_initialize Unexecuted instantiation: region.c:ks_initialize Line | Count | Source | 158 | 12.1k | { | 159 | 12.1k | s->l = s->m = 0; | 160 | | s->s = NULL; | 161 | 12.1k | } |
Unexecuted instantiation: sam_mods.c:ks_initialize Unexecuted instantiation: simd.c:ks_initialize Unexecuted instantiation: textutils.c:ks_initialize Unexecuted instantiation: vcf.c:ks_initialize Unexecuted instantiation: cram_decode.c:ks_initialize Unexecuted instantiation: cram_encode.c:ks_initialize Unexecuted instantiation: cram_index.c:ks_initialize Unexecuted instantiation: cram_io.c:ks_initialize Unexecuted instantiation: cram_stats.c:ks_initialize Unexecuted instantiation: open_trace_file.c:ks_initialize Unexecuted instantiation: hfile_libcurl.c:ks_initialize Unexecuted instantiation: hfile_gcs.c:ks_initialize Line | Count | Source | 158 | 10.0k | { | 159 | 10.0k | s->l = s->m = 0; | 160 | | s->s = NULL; | 161 | 10.0k | } |
Unexecuted instantiation: kstring.c:ks_initialize Unexecuted instantiation: bgzf.c:ks_initialize Unexecuted instantiation: faidx.c:ks_initialize Unexecuted instantiation: md5.c:ks_initialize Unexecuted instantiation: tbx.c:ks_initialize Unexecuted instantiation: cram_codecs.c:ks_initialize |
162 | | |
163 | | /// Resize a kstring to a given capacity |
164 | | static inline int ks_resize(kstring_t *s, size_t size) |
165 | 291M | { |
166 | 291M | if (s->m < size) { |
167 | 17.4M | char *tmp; |
168 | 17.4M | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); |
169 | 17.4M | tmp = (char*)realloc(s->s, size); |
170 | 17.4M | if (!tmp) |
171 | 0 | return -1; |
172 | 17.4M | s->s = tmp; |
173 | 17.4M | s->m = size; |
174 | 17.4M | } |
175 | 291M | return 0; |
176 | 291M | } Unexecuted instantiation: hts_open_fuzzer.c:ks_resize Line | Count | Source | 165 | 4.55M | { | 166 | 4.55M | if (s->m < size) { | 167 | 146k | char *tmp; | 168 | 146k | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 146k | tmp = (char*)realloc(s->s, size); | 170 | 146k | if (!tmp) | 171 | 0 | return -1; | 172 | 146k | s->s = tmp; | 173 | 146k | s->m = size; | 174 | 146k | } | 175 | 4.55M | return 0; | 176 | 4.55M | } |
Unexecuted instantiation: hfile.c:ks_resize Unexecuted instantiation: hts.c:ks_resize Unexecuted instantiation: hts_expr.c:ks_resize Unexecuted instantiation: multipart.c:ks_resize Unexecuted instantiation: region.c:ks_resize Line | Count | Source | 165 | 203M | { | 166 | 203M | if (s->m < size) { | 167 | 42.8k | char *tmp; | 168 | 42.8k | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 42.8k | tmp = (char*)realloc(s->s, size); | 170 | 42.8k | if (!tmp) | 171 | 0 | return -1; | 172 | 42.8k | s->s = tmp; | 173 | 42.8k | s->m = size; | 174 | 42.8k | } | 175 | 203M | return 0; | 176 | 203M | } |
Unexecuted instantiation: sam_mods.c:ks_resize Unexecuted instantiation: simd.c:ks_resize Unexecuted instantiation: textutils.c:ks_resize Line | Count | Source | 165 | 11.0M | { | 166 | 11.0M | if (s->m < size) { | 167 | 96.1k | char *tmp; | 168 | 96.1k | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 96.1k | tmp = (char*)realloc(s->s, size); | 170 | 96.1k | if (!tmp) | 171 | 0 | return -1; | 172 | 96.1k | s->s = tmp; | 173 | 96.1k | s->m = size; | 174 | 96.1k | } | 175 | 11.0M | return 0; | 176 | 11.0M | } |
Unexecuted instantiation: cram_decode.c:ks_resize Line | Count | Source | 165 | 181k | { | 166 | 181k | if (s->m < size) { | 167 | 28.3k | char *tmp; | 168 | 28.3k | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 28.3k | tmp = (char*)realloc(s->s, size); | 170 | 28.3k | if (!tmp) | 171 | 0 | return -1; | 172 | 28.3k | s->s = tmp; | 173 | 28.3k | s->m = size; | 174 | 28.3k | } | 175 | 181k | return 0; | 176 | 181k | } |
Unexecuted instantiation: cram_index.c:ks_resize Unexecuted instantiation: cram_io.c:ks_resize Unexecuted instantiation: cram_stats.c:ks_resize Unexecuted instantiation: open_trace_file.c:ks_resize Unexecuted instantiation: hfile_libcurl.c:ks_resize Line | Count | Source | 165 | 328 | { | 166 | 328 | if (s->m < size) { | 167 | 164 | char *tmp; | 168 | 164 | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 164 | tmp = (char*)realloc(s->s, size); | 170 | 164 | if (!tmp) | 171 | 0 | return -1; | 172 | 164 | s->s = tmp; | 173 | 164 | s->m = size; | 174 | 164 | } | 175 | 328 | return 0; | 176 | 328 | } |
Line | Count | Source | 165 | 70.3k | { | 166 | 70.3k | if (s->m < size) { | 167 | 5.81k | char *tmp; | 168 | 5.81k | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 5.81k | tmp = (char*)realloc(s->s, size); | 170 | 5.81k | if (!tmp) | 171 | 0 | return -1; | 172 | 5.81k | s->s = tmp; | 173 | 5.81k | s->m = size; | 174 | 5.81k | } | 175 | 70.3k | return 0; | 176 | 70.3k | } |
Line | Count | Source | 165 | 1.15M | { | 166 | 1.15M | if (s->m < size) { | 167 | 1.09M | char *tmp; | 168 | 1.09M | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 1.09M | tmp = (char*)realloc(s->s, size); | 170 | 1.09M | if (!tmp) | 171 | 0 | return -1; | 172 | 1.09M | s->s = tmp; | 173 | 1.09M | s->m = size; | 174 | 1.09M | } | 175 | 1.15M | return 0; | 176 | 1.15M | } |
Line | Count | Source | 165 | 67.0M | { | 166 | 67.0M | if (s->m < size) { | 167 | 15.9M | char *tmp; | 168 | 15.9M | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 15.9M | tmp = (char*)realloc(s->s, size); | 170 | 15.9M | if (!tmp) | 171 | 0 | return -1; | 172 | 15.9M | s->s = tmp; | 173 | 15.9M | s->m = size; | 174 | 15.9M | } | 175 | 67.0M | return 0; | 176 | 67.0M | } |
Line | Count | Source | 165 | 3.80M | { | 166 | 3.80M | if (s->m < size) { | 167 | 4.25k | char *tmp; | 168 | 4.25k | size = (size > (SIZE_MAX>>2)) ? size : size + (size >> 1); | 169 | 4.25k | tmp = (char*)realloc(s->s, size); | 170 | 4.25k | if (!tmp) | 171 | 0 | return -1; | 172 | 4.25k | s->s = tmp; | 173 | 4.25k | s->m = size; | 174 | 4.25k | } | 175 | 3.80M | return 0; | 176 | 3.80M | } |
Unexecuted instantiation: md5.c:ks_resize Unexecuted instantiation: tbx.c:ks_resize Unexecuted instantiation: cram_codecs.c:ks_resize |
177 | | |
178 | | /// Increase kstring capacity by a given number of bytes |
179 | | static inline int ks_expand(kstring_t *s, size_t expansion) |
180 | 67.0M | { |
181 | 67.0M | size_t new_size = s->l + expansion; |
182 | | |
183 | 67.0M | if (new_size < s->l) { errno = EOVERFLOW; return -1; } |
184 | 67.0M | return ks_resize(s, new_size); |
185 | 67.0M | } Unexecuted instantiation: hts_open_fuzzer.c:ks_expand Unexecuted instantiation: header.c:ks_expand Unexecuted instantiation: hfile.c:ks_expand Unexecuted instantiation: hts.c:ks_expand Unexecuted instantiation: hts_expr.c:ks_expand Unexecuted instantiation: multipart.c:ks_expand Unexecuted instantiation: region.c:ks_expand Line | Count | Source | 180 | 32.2k | { | 181 | 32.2k | size_t new_size = s->l + expansion; | 182 | | | 183 | 32.2k | if (new_size < s->l) { errno = EOVERFLOW; return -1; } | 184 | 32.2k | return ks_resize(s, new_size); | 185 | 32.2k | } |
Unexecuted instantiation: sam_mods.c:ks_expand Unexecuted instantiation: simd.c:ks_expand Unexecuted instantiation: textutils.c:ks_expand Unexecuted instantiation: vcf.c:ks_expand Unexecuted instantiation: cram_decode.c:ks_expand Unexecuted instantiation: cram_encode.c:ks_expand Unexecuted instantiation: cram_index.c:ks_expand Unexecuted instantiation: cram_io.c:ks_expand Unexecuted instantiation: cram_stats.c:ks_expand Unexecuted instantiation: open_trace_file.c:ks_expand Unexecuted instantiation: hfile_libcurl.c:ks_expand Unexecuted instantiation: hfile_gcs.c:ks_expand Unexecuted instantiation: hfile_s3.c:ks_expand Unexecuted instantiation: kstring.c:ks_expand Line | Count | Source | 180 | 67.0M | { | 181 | 67.0M | size_t new_size = s->l + expansion; | 182 | | | 183 | 67.0M | if (new_size < s->l) { errno = EOVERFLOW; return -1; } | 184 | 67.0M | return ks_resize(s, new_size); | 185 | 67.0M | } |
Unexecuted instantiation: faidx.c:ks_expand Unexecuted instantiation: md5.c:ks_expand Unexecuted instantiation: tbx.c:ks_expand Unexecuted instantiation: cram_codecs.c:ks_expand |
186 | | |
187 | | /// Returns the kstring buffer |
188 | | static inline char *ks_str(kstring_t *s) |
189 | 0 | { |
190 | 0 | return s->s; |
191 | 0 | } Unexecuted instantiation: hts_open_fuzzer.c:ks_str Unexecuted instantiation: header.c:ks_str Unexecuted instantiation: hfile.c:ks_str Unexecuted instantiation: hts.c:ks_str Unexecuted instantiation: hts_expr.c:ks_str Unexecuted instantiation: multipart.c:ks_str Unexecuted instantiation: region.c:ks_str Unexecuted instantiation: sam.c:ks_str Unexecuted instantiation: sam_mods.c:ks_str Unexecuted instantiation: simd.c:ks_str Unexecuted instantiation: textutils.c:ks_str Unexecuted instantiation: vcf.c:ks_str Unexecuted instantiation: cram_decode.c:ks_str Unexecuted instantiation: cram_encode.c:ks_str Unexecuted instantiation: cram_index.c:ks_str Unexecuted instantiation: cram_io.c:ks_str Unexecuted instantiation: cram_stats.c:ks_str Unexecuted instantiation: open_trace_file.c:ks_str Unexecuted instantiation: hfile_libcurl.c:ks_str Unexecuted instantiation: hfile_gcs.c:ks_str Unexecuted instantiation: hfile_s3.c:ks_str Unexecuted instantiation: kstring.c:ks_str Unexecuted instantiation: bgzf.c:ks_str Unexecuted instantiation: faidx.c:ks_str Unexecuted instantiation: md5.c:ks_str Unexecuted instantiation: tbx.c:ks_str Unexecuted instantiation: cram_codecs.c:ks_str |
192 | | |
193 | | /// Returns the kstring buffer, or an empty string if l == 0 |
194 | | /** |
195 | | * Unlike ks_str(), this function will never return NULL. If the kstring is |
196 | | * empty it will return a read-only empty string. As the returned value |
197 | | * may be read-only, the caller should not attempt to modify it. |
198 | | */ |
199 | | static inline const char *ks_c_str(kstring_t *s) |
200 | 0 | { |
201 | 0 | return s->l && s->s ? s->s : ""; |
202 | 0 | } Unexecuted instantiation: hts_open_fuzzer.c:ks_c_str Unexecuted instantiation: header.c:ks_c_str Unexecuted instantiation: hfile.c:ks_c_str Unexecuted instantiation: hts.c:ks_c_str Unexecuted instantiation: hts_expr.c:ks_c_str Unexecuted instantiation: multipart.c:ks_c_str Unexecuted instantiation: region.c:ks_c_str Unexecuted instantiation: sam.c:ks_c_str Unexecuted instantiation: sam_mods.c:ks_c_str Unexecuted instantiation: simd.c:ks_c_str Unexecuted instantiation: textutils.c:ks_c_str Unexecuted instantiation: vcf.c:ks_c_str Unexecuted instantiation: cram_decode.c:ks_c_str Unexecuted instantiation: cram_encode.c:ks_c_str Unexecuted instantiation: cram_index.c:ks_c_str Unexecuted instantiation: cram_io.c:ks_c_str Unexecuted instantiation: cram_stats.c:ks_c_str Unexecuted instantiation: open_trace_file.c:ks_c_str Unexecuted instantiation: hfile_libcurl.c:ks_c_str Unexecuted instantiation: hfile_gcs.c:ks_c_str Unexecuted instantiation: hfile_s3.c:ks_c_str Unexecuted instantiation: kstring.c:ks_c_str Unexecuted instantiation: bgzf.c:ks_c_str Unexecuted instantiation: faidx.c:ks_c_str Unexecuted instantiation: md5.c:ks_c_str Unexecuted instantiation: tbx.c:ks_c_str Unexecuted instantiation: cram_codecs.c:ks_c_str |
203 | | |
204 | | static inline size_t ks_len(kstring_t *s) |
205 | 22 | { |
206 | 22 | return s->l; |
207 | 22 | } Unexecuted instantiation: hts_open_fuzzer.c:ks_len Line | Count | Source | 205 | 22 | { | 206 | 22 | return s->l; | 207 | 22 | } |
Unexecuted instantiation: hfile.c:ks_len Unexecuted instantiation: hts.c:ks_len Unexecuted instantiation: hts_expr.c:ks_len Unexecuted instantiation: multipart.c:ks_len Unexecuted instantiation: region.c:ks_len Unexecuted instantiation: sam.c:ks_len Unexecuted instantiation: sam_mods.c:ks_len Unexecuted instantiation: simd.c:ks_len Unexecuted instantiation: textutils.c:ks_len Unexecuted instantiation: vcf.c:ks_len Unexecuted instantiation: cram_decode.c:ks_len Unexecuted instantiation: cram_encode.c:ks_len Unexecuted instantiation: cram_index.c:ks_len Unexecuted instantiation: cram_io.c:ks_len Unexecuted instantiation: cram_stats.c:ks_len Unexecuted instantiation: open_trace_file.c:ks_len Unexecuted instantiation: hfile_libcurl.c:ks_len Unexecuted instantiation: hfile_gcs.c:ks_len Unexecuted instantiation: hfile_s3.c:ks_len Unexecuted instantiation: kstring.c:ks_len Unexecuted instantiation: bgzf.c:ks_len Unexecuted instantiation: faidx.c:ks_len Unexecuted instantiation: md5.c:ks_len Unexecuted instantiation: tbx.c:ks_len Unexecuted instantiation: cram_codecs.c:ks_len |
208 | | |
209 | | /// Reset kstring length to zero |
210 | | /** |
211 | | @return The kstring itself |
212 | | |
213 | | Example use: kputsn(string, len, ks_clear(s)) |
214 | | */ |
215 | | static inline kstring_t *ks_clear(kstring_t *s) |
216 | 2.53k | { |
217 | 2.53k | s->l = 0; |
218 | 2.53k | return s; |
219 | 2.53k | } Unexecuted instantiation: hts_open_fuzzer.c:ks_clear Unexecuted instantiation: header.c:ks_clear Unexecuted instantiation: hfile.c:ks_clear Unexecuted instantiation: hts.c:ks_clear Unexecuted instantiation: hts_expr.c:ks_clear Unexecuted instantiation: multipart.c:ks_clear Unexecuted instantiation: region.c:ks_clear Unexecuted instantiation: sam.c:ks_clear Unexecuted instantiation: sam_mods.c:ks_clear Unexecuted instantiation: simd.c:ks_clear Unexecuted instantiation: textutils.c:ks_clear Unexecuted instantiation: vcf.c:ks_clear Unexecuted instantiation: cram_decode.c:ks_clear Unexecuted instantiation: cram_encode.c:ks_clear Unexecuted instantiation: cram_index.c:ks_clear Unexecuted instantiation: cram_io.c:ks_clear Unexecuted instantiation: cram_stats.c:ks_clear Unexecuted instantiation: open_trace_file.c:ks_clear Unexecuted instantiation: hfile_libcurl.c:ks_clear Unexecuted instantiation: hfile_gcs.c:ks_clear Line | Count | Source | 216 | 2.53k | { | 217 | 2.53k | s->l = 0; | 218 | 2.53k | return s; | 219 | 2.53k | } |
Unexecuted instantiation: kstring.c:ks_clear Unexecuted instantiation: bgzf.c:ks_clear Unexecuted instantiation: faidx.c:ks_clear Unexecuted instantiation: md5.c:ks_clear Unexecuted instantiation: tbx.c:ks_clear Unexecuted instantiation: cram_codecs.c:ks_clear |
220 | | |
221 | | // Give ownership of the underlying buffer away to something else (making |
222 | | // that something else responsible for freeing it), leaving the kstring_t |
223 | | // empty and ready to be used again, or ready to go out of scope without |
224 | | // needing free(str.s) to prevent a memory leak. |
225 | | static inline char *ks_release(kstring_t *s) |
226 | 49.8k | { |
227 | 49.8k | char *ss = s->s; |
228 | 49.8k | s->l = s->m = 0; |
229 | 49.8k | s->s = NULL; |
230 | 49.8k | return ss; |
231 | 49.8k | } Unexecuted instantiation: hts_open_fuzzer.c:ks_release Line | Count | Source | 226 | 11.8k | { | 227 | 11.8k | char *ss = s->s; | 228 | 11.8k | s->l = s->m = 0; | 229 | | s->s = NULL; | 230 | 11.8k | return ss; | 231 | 11.8k | } |
Unexecuted instantiation: hfile.c:ks_release Unexecuted instantiation: hts.c:ks_release Unexecuted instantiation: hts_expr.c:ks_release Unexecuted instantiation: multipart.c:ks_release Unexecuted instantiation: region.c:ks_release Line | Count | Source | 226 | 37.9k | { | 227 | 37.9k | char *ss = s->s; | 228 | 37.9k | s->l = s->m = 0; | 229 | | s->s = NULL; | 230 | 37.9k | return ss; | 231 | 37.9k | } |
Unexecuted instantiation: sam_mods.c:ks_release Unexecuted instantiation: simd.c:ks_release Unexecuted instantiation: textutils.c:ks_release Unexecuted instantiation: vcf.c:ks_release Unexecuted instantiation: cram_decode.c:ks_release Unexecuted instantiation: cram_encode.c:ks_release Unexecuted instantiation: cram_index.c:ks_release Unexecuted instantiation: cram_io.c:ks_release Unexecuted instantiation: cram_stats.c:ks_release Unexecuted instantiation: open_trace_file.c:ks_release Unexecuted instantiation: hfile_libcurl.c:ks_release Unexecuted instantiation: hfile_gcs.c:ks_release Unexecuted instantiation: hfile_s3.c:ks_release Unexecuted instantiation: kstring.c:ks_release Unexecuted instantiation: bgzf.c:ks_release Unexecuted instantiation: faidx.c:ks_release Unexecuted instantiation: md5.c:ks_release Unexecuted instantiation: tbx.c:ks_release Unexecuted instantiation: cram_codecs.c:ks_release |
232 | | |
233 | | /// Safely free the underlying buffer in a kstring. |
234 | | static inline void ks_free(kstring_t *s) |
235 | 20.1k | { |
236 | 20.1k | if (s) { |
237 | 20.1k | free(s->s); |
238 | 20.1k | ks_initialize(s); |
239 | 20.1k | } |
240 | 20.1k | } Unexecuted instantiation: hts_open_fuzzer.c:ks_free Line | Count | Source | 235 | 1.05k | { | 236 | 1.05k | if (s) { | 237 | 1.05k | free(s->s); | 238 | 1.05k | ks_initialize(s); | 239 | 1.05k | } | 240 | 1.05k | } |
Unexecuted instantiation: hfile.c:ks_free Unexecuted instantiation: hts.c:ks_free Unexecuted instantiation: hts_expr.c:ks_free Unexecuted instantiation: multipart.c:ks_free Unexecuted instantiation: region.c:ks_free Line | Count | Source | 235 | 12.1k | { | 236 | 12.1k | if (s) { | 237 | 12.1k | free(s->s); | 238 | 12.1k | ks_initialize(s); | 239 | 12.1k | } | 240 | 12.1k | } |
Unexecuted instantiation: sam_mods.c:ks_free Unexecuted instantiation: simd.c:ks_free Unexecuted instantiation: textutils.c:ks_free Unexecuted instantiation: vcf.c:ks_free Unexecuted instantiation: cram_decode.c:ks_free Unexecuted instantiation: cram_encode.c:ks_free Unexecuted instantiation: cram_index.c:ks_free Unexecuted instantiation: cram_io.c:ks_free Unexecuted instantiation: cram_stats.c:ks_free Unexecuted instantiation: open_trace_file.c:ks_free Unexecuted instantiation: hfile_libcurl.c:ks_free Unexecuted instantiation: hfile_gcs.c:ks_free Line | Count | Source | 235 | 6.93k | { | 236 | 6.93k | if (s) { | 237 | 6.93k | free(s->s); | 238 | 6.93k | ks_initialize(s); | 239 | 6.93k | } | 240 | 6.93k | } |
Unexecuted instantiation: kstring.c:ks_free Unexecuted instantiation: bgzf.c:ks_free Unexecuted instantiation: faidx.c:ks_free Unexecuted instantiation: md5.c:ks_free Unexecuted instantiation: tbx.c:ks_free Unexecuted instantiation: cram_codecs.c:ks_free |
241 | | |
242 | | static inline int kputsn(const char *p, size_t l, kstring_t *s) |
243 | 63.0M | { |
244 | 63.0M | size_t new_sz = s->l + l + 2; |
245 | 63.0M | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } |
246 | 63.0M | if (ks_resize(s, new_sz) < 0) return EOF; |
247 | 63.0M | memcpy(s->s + s->l, p, l); |
248 | 63.0M | s->l += l; |
249 | 63.0M | s->s[s->l] = 0; |
250 | 63.0M | return l; |
251 | 63.0M | } Unexecuted instantiation: hts_open_fuzzer.c:kputsn Line | Count | Source | 243 | 2.19M | { | 244 | 2.19M | size_t new_sz = s->l + l + 2; | 245 | 2.19M | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 2.19M | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 2.19M | memcpy(s->s + s->l, p, l); | 248 | 2.19M | s->l += l; | 249 | 2.19M | s->s[s->l] = 0; | 250 | 2.19M | return l; | 251 | 2.19M | } |
Unexecuted instantiation: hfile.c:kputsn Unexecuted instantiation: hts.c:kputsn Unexecuted instantiation: hts_expr.c:kputsn Unexecuted instantiation: multipart.c:kputsn Unexecuted instantiation: region.c:kputsn Line | Count | Source | 243 | 57.1M | { | 244 | 57.1M | size_t new_sz = s->l + l + 2; | 245 | 57.1M | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 57.1M | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 57.1M | memcpy(s->s + s->l, p, l); | 248 | 57.1M | s->l += l; | 249 | 57.1M | s->s[s->l] = 0; | 250 | 57.1M | return l; | 251 | 57.1M | } |
Unexecuted instantiation: sam_mods.c:kputsn Unexecuted instantiation: simd.c:kputsn Unexecuted instantiation: textutils.c:kputsn Line | Count | Source | 243 | 3.61M | { | 244 | 3.61M | size_t new_sz = s->l + l + 2; | 245 | 3.61M | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 3.61M | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 3.61M | memcpy(s->s + s->l, p, l); | 248 | 3.61M | s->l += l; | 249 | 3.61M | s->s[s->l] = 0; | 250 | 3.61M | return l; | 251 | 3.61M | } |
Unexecuted instantiation: cram_decode.c:kputsn Line | Count | Source | 243 | 19.8k | { | 244 | 19.8k | size_t new_sz = s->l + l + 2; | 245 | 19.8k | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 19.8k | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 19.8k | memcpy(s->s + s->l, p, l); | 248 | 19.8k | s->l += l; | 249 | 19.8k | s->s[s->l] = 0; | 250 | 19.8k | return l; | 251 | 19.8k | } |
Unexecuted instantiation: cram_index.c:kputsn Unexecuted instantiation: cram_io.c:kputsn Unexecuted instantiation: cram_stats.c:kputsn Unexecuted instantiation: open_trace_file.c:kputsn Unexecuted instantiation: hfile_libcurl.c:kputsn Line | Count | Source | 243 | 325 | { | 244 | 325 | size_t new_sz = s->l + l + 2; | 245 | 325 | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 325 | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 325 | memcpy(s->s + s->l, p, l); | 248 | 325 | s->l += l; | 249 | 325 | s->s[s->l] = 0; | 250 | 325 | return l; | 251 | 325 | } |
Line | Count | Source | 243 | 5.47k | { | 244 | 5.47k | size_t new_sz = s->l + l + 2; | 245 | 5.47k | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 5.47k | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 5.47k | memcpy(s->s + s->l, p, l); | 248 | 5.47k | s->l += l; | 249 | 5.47k | s->s[s->l] = 0; | 250 | 5.47k | return l; | 251 | 5.47k | } |
Line | Count | Source | 243 | 55.6k | { | 244 | 55.6k | size_t new_sz = s->l + l + 2; | 245 | 55.6k | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 55.6k | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 55.6k | memcpy(s->s + s->l, p, l); | 248 | 55.6k | s->l += l; | 249 | 55.6k | s->s[s->l] = 0; | 250 | 55.6k | return l; | 251 | 55.6k | } |
Unexecuted instantiation: bgzf.c:kputsn Line | Count | Source | 243 | 11.9k | { | 244 | 11.9k | size_t new_sz = s->l + l + 2; | 245 | 11.9k | if (new_sz <= s->l) { errno = EOVERFLOW; return EOF; } | 246 | 11.9k | if (ks_resize(s, new_sz) < 0) return EOF; | 247 | 11.9k | memcpy(s->s + s->l, p, l); | 248 | 11.9k | s->l += l; | 249 | 11.9k | s->s[s->l] = 0; | 250 | 11.9k | return l; | 251 | 11.9k | } |
Unexecuted instantiation: md5.c:kputsn Unexecuted instantiation: tbx.c:kputsn Unexecuted instantiation: cram_codecs.c:kputsn |
252 | | |
253 | | static inline int kputs(const char *p, kstring_t *s) |
254 | 1.26M | { |
255 | 1.26M | if (!p) { errno = EFAULT; return -1; } |
256 | 1.26M | return kputsn(p, strlen(p), s); |
257 | 1.26M | } Unexecuted instantiation: hts_open_fuzzer.c:kputs Unexecuted instantiation: header.c:kputs Unexecuted instantiation: hfile.c:kputs Unexecuted instantiation: hts.c:kputs Unexecuted instantiation: hts_expr.c:kputs Unexecuted instantiation: multipart.c:kputs Unexecuted instantiation: region.c:kputs Line | Count | Source | 254 | 65.9k | { | 255 | 65.9k | if (!p) { errno = EFAULT; return -1; } | 256 | 65.9k | return kputsn(p, strlen(p), s); | 257 | 65.9k | } |
Unexecuted instantiation: sam_mods.c:kputs Unexecuted instantiation: simd.c:kputs Unexecuted instantiation: textutils.c:kputs Line | Count | Source | 254 | 1.19M | { | 255 | 1.19M | if (!p) { errno = EFAULT; return -1; } | 256 | 1.19M | return kputsn(p, strlen(p), s); | 257 | 1.19M | } |
Unexecuted instantiation: cram_decode.c:kputs Unexecuted instantiation: cram_encode.c:kputs Unexecuted instantiation: cram_index.c:kputs Unexecuted instantiation: cram_io.c:kputs Unexecuted instantiation: cram_stats.c:kputs Unexecuted instantiation: open_trace_file.c:kputs Unexecuted instantiation: hfile_libcurl.c:kputs Line | Count | Source | 254 | 251 | { | 255 | 251 | if (!p) { errno = EFAULT; return -1; } | 256 | 251 | return kputsn(p, strlen(p), s); | 257 | 251 | } |
Line | Count | Source | 254 | 4.20k | { | 255 | 4.20k | if (!p) { errno = EFAULT; return -1; } | 256 | 4.20k | return kputsn(p, strlen(p), s); | 257 | 4.20k | } |
Unexecuted instantiation: kstring.c:kputs Unexecuted instantiation: bgzf.c:kputs Unexecuted instantiation: faidx.c:kputs Unexecuted instantiation: md5.c:kputs Unexecuted instantiation: tbx.c:kputs Unexecuted instantiation: cram_codecs.c:kputs |
258 | | |
259 | | static inline int kputc(int c, kstring_t *s) |
260 | 8.48M | { |
261 | 8.48M | if (ks_resize(s, s->l + 2) < 0) |
262 | 0 | return EOF; |
263 | 8.48M | s->s[s->l++] = c; |
264 | 8.48M | s->s[s->l] = 0; |
265 | 8.48M | return (unsigned char)c; |
266 | 8.48M | } Unexecuted instantiation: hts_open_fuzzer.c:kputc Line | Count | Source | 260 | 1.88M | { | 261 | 1.88M | if (ks_resize(s, s->l + 2) < 0) | 262 | 0 | return EOF; | 263 | 1.88M | s->s[s->l++] = c; | 264 | 1.88M | s->s[s->l] = 0; | 265 | 1.88M | return (unsigned char)c; | 266 | 1.88M | } |
Unexecuted instantiation: hfile.c:kputc Unexecuted instantiation: hts.c:kputc Unexecuted instantiation: hts_expr.c:kputc Unexecuted instantiation: multipart.c:kputc Unexecuted instantiation: region.c:kputc Line | Count | Source | 260 | 5.97M | { | 261 | 5.97M | if (ks_resize(s, s->l + 2) < 0) | 262 | 0 | return EOF; | 263 | 5.97M | s->s[s->l++] = c; | 264 | 5.97M | s->s[s->l] = 0; | 265 | 5.97M | return (unsigned char)c; | 266 | 5.97M | } |
Unexecuted instantiation: sam_mods.c:kputc Unexecuted instantiation: simd.c:kputc Unexecuted instantiation: textutils.c:kputc Line | Count | Source | 260 | 519k | { | 261 | 519k | if (ks_resize(s, s->l + 2) < 0) | 262 | 0 | return EOF; | 263 | 519k | s->s[s->l++] = c; | 264 | 519k | s->s[s->l] = 0; | 265 | 519k | return (unsigned char)c; | 266 | 519k | } |
Unexecuted instantiation: cram_decode.c:kputc Line | Count | Source | 260 | 37.1k | { | 261 | 37.1k | if (ks_resize(s, s->l + 2) < 0) | 262 | 0 | return EOF; | 263 | 37.1k | s->s[s->l++] = c; | 264 | 37.1k | s->s[s->l] = 0; | 265 | 37.1k | return (unsigned char)c; | 266 | 37.1k | } |
Unexecuted instantiation: cram_index.c:kputc Unexecuted instantiation: cram_io.c:kputc Unexecuted instantiation: cram_stats.c:kputc Unexecuted instantiation: open_trace_file.c:kputc Unexecuted instantiation: hfile_libcurl.c:kputc Line | Count | Source | 260 | 3 | { | 261 | 3 | if (ks_resize(s, s->l + 2) < 0) | 262 | 0 | return EOF; | 263 | 3 | s->s[s->l++] = c; | 264 | 3 | s->s[s->l] = 0; | 265 | 3 | return (unsigned char)c; | 266 | 3 | } |
Line | Count | Source | 260 | 64.8k | { | 261 | 64.8k | if (ks_resize(s, s->l + 2) < 0) | 262 | 0 | return EOF; | 263 | 64.8k | s->s[s->l++] = c; | 264 | 64.8k | s->s[s->l] = 0; | 265 | 64.8k | return (unsigned char)c; | 266 | 64.8k | } |
Line | Count | Source | 260 | 1.38k | { | 261 | 1.38k | if (ks_resize(s, s->l + 2) < 0) | 262 | 0 | return EOF; | 263 | 1.38k | s->s[s->l++] = c; | 264 | 1.38k | s->s[s->l] = 0; | 265 | 1.38k | return (unsigned char)c; | 266 | 1.38k | } |
Unexecuted instantiation: bgzf.c:kputc Unexecuted instantiation: faidx.c:kputc Unexecuted instantiation: md5.c:kputc Unexecuted instantiation: tbx.c:kputc Unexecuted instantiation: cram_codecs.c:kputc |
267 | | |
268 | | static inline int kputc_(int c, kstring_t *s) |
269 | 78.0M | { |
270 | 78.0M | if (ks_resize(s, s->l + 1) < 0) |
271 | 0 | return EOF; |
272 | 78.0M | s->s[s->l++] = c; |
273 | 78.0M | return 1; |
274 | 78.0M | } Unexecuted instantiation: hts_open_fuzzer.c:kputc_ Line | Count | Source | 269 | 478k | { | 270 | 478k | if (ks_resize(s, s->l + 1) < 0) | 271 | 0 | return EOF; | 272 | 478k | s->s[s->l++] = c; | 273 | 478k | return 1; | 274 | 478k | } |
Unexecuted instantiation: hfile.c:kputc_ Unexecuted instantiation: hts.c:kputc_ Unexecuted instantiation: hts_expr.c:kputc_ Unexecuted instantiation: multipart.c:kputc_ Unexecuted instantiation: region.c:kputc_ Line | Count | Source | 269 | 70.0M | { | 270 | 70.0M | if (ks_resize(s, s->l + 1) < 0) | 271 | 0 | return EOF; | 272 | 70.0M | s->s[s->l++] = c; | 273 | 70.0M | return 1; | 274 | 70.0M | } |
Unexecuted instantiation: sam_mods.c:kputc_ Unexecuted instantiation: simd.c:kputc_ Unexecuted instantiation: textutils.c:kputc_ Line | Count | Source | 269 | 3.74M | { | 270 | 3.74M | if (ks_resize(s, s->l + 1) < 0) | 271 | 0 | return EOF; | 272 | 3.74M | s->s[s->l++] = c; | 273 | 3.74M | return 1; | 274 | 3.74M | } |
Unexecuted instantiation: cram_decode.c:kputc_ Line | Count | Source | 269 | 19.8k | { | 270 | 19.8k | if (ks_resize(s, s->l + 1) < 0) | 271 | 0 | return EOF; | 272 | 19.8k | s->s[s->l++] = c; | 273 | 19.8k | return 1; | 274 | 19.8k | } |
Unexecuted instantiation: cram_index.c:kputc_ Unexecuted instantiation: cram_io.c:kputc_ Unexecuted instantiation: cram_stats.c:kputc_ Unexecuted instantiation: open_trace_file.c:kputc_ Unexecuted instantiation: hfile_libcurl.c:kputc_ Unexecuted instantiation: hfile_gcs.c:kputc_ Unexecuted instantiation: hfile_s3.c:kputc_ Unexecuted instantiation: kstring.c:kputc_ Unexecuted instantiation: bgzf.c:kputc_ Line | Count | Source | 269 | 3.79M | { | 270 | 3.79M | if (ks_resize(s, s->l + 1) < 0) | 271 | 0 | return EOF; | 272 | 3.79M | s->s[s->l++] = c; | 273 | 3.79M | return 1; | 274 | 3.79M | } |
Unexecuted instantiation: md5.c:kputc_ Unexecuted instantiation: tbx.c:kputc_ Unexecuted instantiation: cram_codecs.c:kputc_ |
275 | | |
276 | | static inline int kputsn_(const void *p, size_t l, kstring_t *s) |
277 | 23.8M | { |
278 | 23.8M | size_t new_sz = s->l + l; |
279 | 23.8M | if (new_sz < s->l) { errno = EOVERFLOW; return EOF; } |
280 | 23.8M | if (ks_resize(s, new_sz ? new_sz : 1) < 0) return EOF; |
281 | 23.8M | memcpy(s->s + s->l, p, l); |
282 | 23.8M | s->l += l; |
283 | 23.8M | return l; |
284 | 23.8M | } Unexecuted instantiation: hts_open_fuzzer.c:kputsn_ Unexecuted instantiation: header.c:kputsn_ Unexecuted instantiation: hfile.c:kputsn_ Unexecuted instantiation: hts.c:kputsn_ Unexecuted instantiation: hts_expr.c:kputsn_ Unexecuted instantiation: multipart.c:kputsn_ Unexecuted instantiation: region.c:kputsn_ Line | Count | Source | 277 | 23.8M | { | 278 | 23.8M | size_t new_sz = s->l + l; | 279 | 23.8M | if (new_sz < s->l) { errno = EOVERFLOW; return EOF; } | 280 | 23.8M | if (ks_resize(s, new_sz ? new_sz : 1) < 0) return EOF; | 281 | 23.8M | memcpy(s->s + s->l, p, l); | 282 | 23.8M | s->l += l; | 283 | 23.8M | return l; | 284 | 23.8M | } |
Unexecuted instantiation: sam_mods.c:kputsn_ Unexecuted instantiation: simd.c:kputsn_ Unexecuted instantiation: textutils.c:kputsn_ Unexecuted instantiation: vcf.c:kputsn_ Unexecuted instantiation: cram_decode.c:kputsn_ Unexecuted instantiation: cram_encode.c:kputsn_ Unexecuted instantiation: cram_index.c:kputsn_ Unexecuted instantiation: cram_io.c:kputsn_ Unexecuted instantiation: cram_stats.c:kputsn_ Unexecuted instantiation: open_trace_file.c:kputsn_ Unexecuted instantiation: hfile_libcurl.c:kputsn_ Unexecuted instantiation: hfile_gcs.c:kputsn_ Line | Count | Source | 277 | 33 | { | 278 | 33 | size_t new_sz = s->l + l; | 279 | 33 | if (new_sz < s->l) { errno = EOVERFLOW; return EOF; } | 280 | 33 | if (ks_resize(s, new_sz ? new_sz : 1) < 0) return EOF; | 281 | 33 | memcpy(s->s + s->l, p, l); | 282 | 33 | s->l += l; | 283 | 33 | return l; | 284 | 33 | } |
Unexecuted instantiation: kstring.c:kputsn_ Unexecuted instantiation: bgzf.c:kputsn_ Unexecuted instantiation: faidx.c:kputsn_ Unexecuted instantiation: md5.c:kputsn_ Unexecuted instantiation: tbx.c:kputsn_ Unexecuted instantiation: cram_codecs.c:kputsn_ |
285 | | |
286 | | static inline int kputuw(unsigned x, kstring_t *s) |
287 | 29.7M | { |
288 | 29.7M | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U |
289 | 29.7M | static const unsigned int kputuw_num_digits[32] = { |
290 | 29.7M | 10, 10, 10, 9, 9, 9, 8, 8, |
291 | 29.7M | 8, 7, 7, 7, 7, 6, 6, 6, |
292 | 29.7M | 5, 5, 5, 4, 4, 4, 4, 3, |
293 | 29.7M | 3, 3, 2, 2, 2, 1, 1, 1 |
294 | 29.7M | }; |
295 | 29.7M | static const unsigned int kputuw_thresholds[32] = { |
296 | 29.7M | 0, 0, 1000000000U, 0, 0, 100000000U, 0, 0, |
297 | 29.7M | 10000000, 0, 0, 0, 1000000, 0, 0, 100000, |
298 | 29.7M | 0, 0, 10000, 0, 0, 0, 1000, 0, |
299 | 29.7M | 0, 100, 0, 0, 10, 0, 0, 0 |
300 | 29.7M | }; |
301 | | #else |
302 | | uint64_t m; |
303 | | #endif |
304 | 29.7M | static const char kputuw_dig2r[] = |
305 | 29.7M | "00010203040506070809" |
306 | 29.7M | "10111213141516171819" |
307 | 29.7M | "20212223242526272829" |
308 | 29.7M | "30313233343536373839" |
309 | 29.7M | "40414243444546474849" |
310 | 29.7M | "50515253545556575859" |
311 | 29.7M | "60616263646566676869" |
312 | 29.7M | "70717273747576777879" |
313 | 29.7M | "80818283848586878889" |
314 | 29.7M | "90919293949596979899"; |
315 | 29.7M | unsigned int l, j; |
316 | 29.7M | char *cp; |
317 | | |
318 | | // Trivial case - also prevents __builtin_clz(0), which is undefined |
319 | 29.7M | if (x < 10) { |
320 | 28.8M | if (ks_resize(s, s->l + 2) < 0) |
321 | 0 | return EOF; |
322 | 28.8M | s->s[s->l++] = '0'+x; |
323 | 28.8M | s->s[s->l] = 0; |
324 | 28.8M | return 0; |
325 | 28.8M | } |
326 | | |
327 | | // Find out how many digits are to be printed. |
328 | 885k | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U |
329 | | /* |
330 | | * Table method - should be quick if clz can be done in hardware. |
331 | | * Find the most significant bit of the value to print and look |
332 | | * up in a table to find out how many decimal digits are needed. |
333 | | * This number needs to be adjusted by 1 for cases where the decimal |
334 | | * length could vary for a given number of bits (for example, |
335 | | * a four bit number could be between 8 and 15). |
336 | | */ |
337 | | |
338 | 885k | l = __builtin_clz(x); |
339 | 885k | l = kputuw_num_digits[l] - (x < kputuw_thresholds[l]); |
340 | | #else |
341 | | // Fallback for when clz is not available |
342 | | m = 1; |
343 | | l = 0; |
344 | | do { |
345 | | l++; |
346 | | m *= 10; |
347 | | } while (x >= m); |
348 | | #endif |
349 | | |
350 | 885k | if (ks_resize(s, s->l + l + 2) < 0) |
351 | 0 | return EOF; |
352 | | |
353 | | // Add digits two at a time |
354 | 885k | j = l; |
355 | 885k | cp = s->s + s->l; |
356 | 2.35M | while (x >= 10) { |
357 | 1.46M | const char *d = &kputuw_dig2r[2*(x%100)]; |
358 | 1.46M | x /= 100; |
359 | 1.46M | memcpy(&cp[j-=2], d, 2); |
360 | 1.46M | } |
361 | | |
362 | | // Last one (if necessary). We know that x < 10 by now. |
363 | 885k | if (j == 1) |
364 | 468k | cp[0] = x + '0'; |
365 | | |
366 | 885k | s->l += l; |
367 | 885k | s->s[s->l] = 0; |
368 | 885k | return 0; |
369 | 885k | } Unexecuted instantiation: hts_open_fuzzer.c:kputuw Unexecuted instantiation: header.c:kputuw Unexecuted instantiation: hfile.c:kputuw Unexecuted instantiation: hts.c:kputuw Unexecuted instantiation: hts_expr.c:kputuw Unexecuted instantiation: multipart.c:kputuw Unexecuted instantiation: region.c:kputuw Line | Count | Source | 287 | 29.5M | { | 288 | 29.5M | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U | 289 | 29.5M | static const unsigned int kputuw_num_digits[32] = { | 290 | 29.5M | 10, 10, 10, 9, 9, 9, 8, 8, | 291 | 29.5M | 8, 7, 7, 7, 7, 6, 6, 6, | 292 | 29.5M | 5, 5, 5, 4, 4, 4, 4, 3, | 293 | 29.5M | 3, 3, 2, 2, 2, 1, 1, 1 | 294 | 29.5M | }; | 295 | 29.5M | static const unsigned int kputuw_thresholds[32] = { | 296 | 29.5M | 0, 0, 1000000000U, 0, 0, 100000000U, 0, 0, | 297 | 29.5M | 10000000, 0, 0, 0, 1000000, 0, 0, 100000, | 298 | 29.5M | 0, 0, 10000, 0, 0, 0, 1000, 0, | 299 | 29.5M | 0, 100, 0, 0, 10, 0, 0, 0 | 300 | 29.5M | }; | 301 | | #else | 302 | | uint64_t m; | 303 | | #endif | 304 | 29.5M | static const char kputuw_dig2r[] = | 305 | 29.5M | "00010203040506070809" | 306 | 29.5M | "10111213141516171819" | 307 | 29.5M | "20212223242526272829" | 308 | 29.5M | "30313233343536373839" | 309 | 29.5M | "40414243444546474849" | 310 | 29.5M | "50515253545556575859" | 311 | 29.5M | "60616263646566676869" | 312 | 29.5M | "70717273747576777879" | 313 | 29.5M | "80818283848586878889" | 314 | 29.5M | "90919293949596979899"; | 315 | 29.5M | unsigned int l, j; | 316 | 29.5M | char *cp; | 317 | | | 318 | | // Trivial case - also prevents __builtin_clz(0), which is undefined | 319 | 29.5M | if (x < 10) { | 320 | 28.7M | if (ks_resize(s, s->l + 2) < 0) | 321 | 0 | return EOF; | 322 | 28.7M | s->s[s->l++] = '0'+x; | 323 | 28.7M | s->s[s->l] = 0; | 324 | 28.7M | return 0; | 325 | 28.7M | } | 326 | | | 327 | | // Find out how many digits are to be printed. | 328 | 838k | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U | 329 | | /* | 330 | | * Table method - should be quick if clz can be done in hardware. | 331 | | * Find the most significant bit of the value to print and look | 332 | | * up in a table to find out how many decimal digits are needed. | 333 | | * This number needs to be adjusted by 1 for cases where the decimal | 334 | | * length could vary for a given number of bits (for example, | 335 | | * a four bit number could be between 8 and 15). | 336 | | */ | 337 | | | 338 | 838k | l = __builtin_clz(x); | 339 | 838k | l = kputuw_num_digits[l] - (x < kputuw_thresholds[l]); | 340 | | #else | 341 | | // Fallback for when clz is not available | 342 | | m = 1; | 343 | | l = 0; | 344 | | do { | 345 | | l++; | 346 | | m *= 10; | 347 | | } while (x >= m); | 348 | | #endif | 349 | | | 350 | 838k | if (ks_resize(s, s->l + l + 2) < 0) | 351 | 0 | return EOF; | 352 | | | 353 | | // Add digits two at a time | 354 | 838k | j = l; | 355 | 838k | cp = s->s + s->l; | 356 | 2.23M | while (x >= 10) { | 357 | 1.39M | const char *d = &kputuw_dig2r[2*(x%100)]; | 358 | 1.39M | x /= 100; | 359 | 1.39M | memcpy(&cp[j-=2], d, 2); | 360 | 1.39M | } | 361 | | | 362 | | // Last one (if necessary). We know that x < 10 by now. | 363 | 838k | if (j == 1) | 364 | 456k | cp[0] = x + '0'; | 365 | | | 366 | 838k | s->l += l; | 367 | 838k | s->s[s->l] = 0; | 368 | 838k | return 0; | 369 | 838k | } |
Unexecuted instantiation: sam_mods.c:kputuw Unexecuted instantiation: simd.c:kputuw Unexecuted instantiation: textutils.c:kputuw Line | Count | Source | 287 | 101k | { | 288 | 101k | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U | 289 | 101k | static const unsigned int kputuw_num_digits[32] = { | 290 | 101k | 10, 10, 10, 9, 9, 9, 8, 8, | 291 | 101k | 8, 7, 7, 7, 7, 6, 6, 6, | 292 | 101k | 5, 5, 5, 4, 4, 4, 4, 3, | 293 | 101k | 3, 3, 2, 2, 2, 1, 1, 1 | 294 | 101k | }; | 295 | 101k | static const unsigned int kputuw_thresholds[32] = { | 296 | 101k | 0, 0, 1000000000U, 0, 0, 100000000U, 0, 0, | 297 | 101k | 10000000, 0, 0, 0, 1000000, 0, 0, 100000, | 298 | 101k | 0, 0, 10000, 0, 0, 0, 1000, 0, | 299 | 101k | 0, 100, 0, 0, 10, 0, 0, 0 | 300 | 101k | }; | 301 | | #else | 302 | | uint64_t m; | 303 | | #endif | 304 | 101k | static const char kputuw_dig2r[] = | 305 | 101k | "00010203040506070809" | 306 | 101k | "10111213141516171819" | 307 | 101k | "20212223242526272829" | 308 | 101k | "30313233343536373839" | 309 | 101k | "40414243444546474849" | 310 | 101k | "50515253545556575859" | 311 | 101k | "60616263646566676869" | 312 | 101k | "70717273747576777879" | 313 | 101k | "80818283848586878889" | 314 | 101k | "90919293949596979899"; | 315 | 101k | unsigned int l, j; | 316 | 101k | char *cp; | 317 | | | 318 | | // Trivial case - also prevents __builtin_clz(0), which is undefined | 319 | 101k | if (x < 10) { | 320 | 60.6k | if (ks_resize(s, s->l + 2) < 0) | 321 | 0 | return EOF; | 322 | 60.6k | s->s[s->l++] = '0'+x; | 323 | 60.6k | s->s[s->l] = 0; | 324 | 60.6k | return 0; | 325 | 60.6k | } | 326 | | | 327 | | // Find out how many digits are to be printed. | 328 | 41.1k | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U | 329 | | /* | 330 | | * Table method - should be quick if clz can be done in hardware. | 331 | | * Find the most significant bit of the value to print and look | 332 | | * up in a table to find out how many decimal digits are needed. | 333 | | * This number needs to be adjusted by 1 for cases where the decimal | 334 | | * length could vary for a given number of bits (for example, | 335 | | * a four bit number could be between 8 and 15). | 336 | | */ | 337 | | | 338 | 41.1k | l = __builtin_clz(x); | 339 | 41.1k | l = kputuw_num_digits[l] - (x < kputuw_thresholds[l]); | 340 | | #else | 341 | | // Fallback for when clz is not available | 342 | | m = 1; | 343 | | l = 0; | 344 | | do { | 345 | | l++; | 346 | | m *= 10; | 347 | | } while (x >= m); | 348 | | #endif | 349 | | | 350 | 41.1k | if (ks_resize(s, s->l + l + 2) < 0) | 351 | 0 | return EOF; | 352 | | | 353 | | // Add digits two at a time | 354 | 41.1k | j = l; | 355 | 41.1k | cp = s->s + s->l; | 356 | 101k | while (x >= 10) { | 357 | 60.4k | const char *d = &kputuw_dig2r[2*(x%100)]; | 358 | 60.4k | x /= 100; | 359 | 60.4k | memcpy(&cp[j-=2], d, 2); | 360 | 60.4k | } | 361 | | | 362 | | // Last one (if necessary). We know that x < 10 by now. | 363 | 41.1k | if (j == 1) | 364 | 11.8k | cp[0] = x + '0'; | 365 | | | 366 | 41.1k | s->l += l; | 367 | 41.1k | s->s[s->l] = 0; | 368 | 41.1k | return 0; | 369 | 41.1k | } |
Unexecuted instantiation: cram_decode.c:kputuw Line | Count | Source | 287 | 104k | { | 288 | 104k | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U | 289 | 104k | static const unsigned int kputuw_num_digits[32] = { | 290 | 104k | 10, 10, 10, 9, 9, 9, 8, 8, | 291 | 104k | 8, 7, 7, 7, 7, 6, 6, 6, | 292 | 104k | 5, 5, 5, 4, 4, 4, 4, 3, | 293 | 104k | 3, 3, 2, 2, 2, 1, 1, 1 | 294 | 104k | }; | 295 | 104k | static const unsigned int kputuw_thresholds[32] = { | 296 | 104k | 0, 0, 1000000000U, 0, 0, 100000000U, 0, 0, | 297 | 104k | 10000000, 0, 0, 0, 1000000, 0, 0, 100000, | 298 | 104k | 0, 0, 10000, 0, 0, 0, 1000, 0, | 299 | 104k | 0, 100, 0, 0, 10, 0, 0, 0 | 300 | 104k | }; | 301 | | #else | 302 | | uint64_t m; | 303 | | #endif | 304 | 104k | static const char kputuw_dig2r[] = | 305 | 104k | "00010203040506070809" | 306 | 104k | "10111213141516171819" | 307 | 104k | "20212223242526272829" | 308 | 104k | "30313233343536373839" | 309 | 104k | "40414243444546474849" | 310 | 104k | "50515253545556575859" | 311 | 104k | "60616263646566676869" | 312 | 104k | "70717273747576777879" | 313 | 104k | "80818283848586878889" | 314 | 104k | "90919293949596979899"; | 315 | 104k | unsigned int l, j; | 316 | 104k | char *cp; | 317 | | | 318 | | // Trivial case - also prevents __builtin_clz(0), which is undefined | 319 | 104k | if (x < 10) { | 320 | 98.1k | if (ks_resize(s, s->l + 2) < 0) | 321 | 0 | return EOF; | 322 | 98.1k | s->s[s->l++] = '0'+x; | 323 | 98.1k | s->s[s->l] = 0; | 324 | 98.1k | return 0; | 325 | 98.1k | } | 326 | | | 327 | | // Find out how many digits are to be printed. | 328 | 6.35k | #if HAVE___BUILTIN_CLZ && UINT_MAX == 4294967295U | 329 | | /* | 330 | | * Table method - should be quick if clz can be done in hardware. | 331 | | * Find the most significant bit of the value to print and look | 332 | | * up in a table to find out how many decimal digits are needed. | 333 | | * This number needs to be adjusted by 1 for cases where the decimal | 334 | | * length could vary for a given number of bits (for example, | 335 | | * a four bit number could be between 8 and 15). | 336 | | */ | 337 | | | 338 | 6.35k | l = __builtin_clz(x); | 339 | 6.35k | l = kputuw_num_digits[l] - (x < kputuw_thresholds[l]); | 340 | | #else | 341 | | // Fallback for when clz is not available | 342 | | m = 1; | 343 | | l = 0; | 344 | | do { | 345 | | l++; | 346 | | m *= 10; | 347 | | } while (x >= m); | 348 | | #endif | 349 | | | 350 | 6.35k | if (ks_resize(s, s->l + l + 2) < 0) | 351 | 0 | return EOF; | 352 | | | 353 | | // Add digits two at a time | 354 | 6.35k | j = l; | 355 | 6.35k | cp = s->s + s->l; | 356 | 12.7k | while (x >= 10) { | 357 | 6.35k | const char *d = &kputuw_dig2r[2*(x%100)]; | 358 | 6.35k | x /= 100; | 359 | 6.35k | memcpy(&cp[j-=2], d, 2); | 360 | 6.35k | } | 361 | | | 362 | | // Last one (if necessary). We know that x < 10 by now. | 363 | 6.35k | if (j == 1) | 364 | 0 | cp[0] = x + '0'; | 365 | | | 366 | 6.35k | s->l += l; | 367 | 6.35k | s->s[s->l] = 0; | 368 | 6.35k | return 0; | 369 | 6.35k | } |
Unexecuted instantiation: cram_index.c:kputuw Unexecuted instantiation: cram_io.c:kputuw Unexecuted instantiation: cram_stats.c:kputuw Unexecuted instantiation: open_trace_file.c:kputuw Unexecuted instantiation: hfile_libcurl.c:kputuw Unexecuted instantiation: hfile_gcs.c:kputuw Unexecuted instantiation: hfile_s3.c:kputuw Unexecuted instantiation: kstring.c:kputuw Unexecuted instantiation: bgzf.c:kputuw Unexecuted instantiation: faidx.c:kputuw Unexecuted instantiation: md5.c:kputuw Unexecuted instantiation: tbx.c:kputuw Unexecuted instantiation: cram_codecs.c:kputuw |
370 | | |
371 | | static inline int kputw(int c, kstring_t *s) |
372 | 13.0M | { |
373 | 13.0M | unsigned int x = c; |
374 | 13.0M | if (c < 0) { |
375 | 438k | x = -x; |
376 | 438k | if (ks_resize(s, s->l + 3) < 0) |
377 | 0 | return EOF; |
378 | 438k | s->s[s->l++] = '-'; |
379 | 438k | } |
380 | | |
381 | 13.0M | return kputuw(x, s); |
382 | 13.0M | } Unexecuted instantiation: hts_open_fuzzer.c:kputw Unexecuted instantiation: header.c:kputw Unexecuted instantiation: hfile.c:kputw Unexecuted instantiation: hts.c:kputw Unexecuted instantiation: hts_expr.c:kputw Unexecuted instantiation: multipart.c:kputw Unexecuted instantiation: region.c:kputw Line | Count | Source | 372 | 12.9M | { | 373 | 12.9M | unsigned int x = c; | 374 | 12.9M | if (c < 0) { | 375 | 426k | x = -x; | 376 | 426k | if (ks_resize(s, s->l + 3) < 0) | 377 | 0 | return EOF; | 378 | 426k | s->s[s->l++] = '-'; | 379 | 426k | } | 380 | | | 381 | 12.9M | return kputuw(x, s); | 382 | 12.9M | } |
Unexecuted instantiation: sam_mods.c:kputw Unexecuted instantiation: simd.c:kputw Unexecuted instantiation: textutils.c:kputw Line | Count | Source | 372 | 67.8k | { | 373 | 67.8k | unsigned int x = c; | 374 | 67.8k | if (c < 0) { | 375 | 12.2k | x = -x; | 376 | 12.2k | if (ks_resize(s, s->l + 3) < 0) | 377 | 0 | return EOF; | 378 | 12.2k | s->s[s->l++] = '-'; | 379 | 12.2k | } | 380 | | | 381 | 67.8k | return kputuw(x, s); | 382 | 67.8k | } |
Unexecuted instantiation: cram_decode.c:kputw Unexecuted instantiation: cram_encode.c:kputw Unexecuted instantiation: cram_index.c:kputw Unexecuted instantiation: cram_io.c:kputw Unexecuted instantiation: cram_stats.c:kputw Unexecuted instantiation: open_trace_file.c:kputw Unexecuted instantiation: hfile_libcurl.c:kputw Unexecuted instantiation: hfile_gcs.c:kputw Unexecuted instantiation: hfile_s3.c:kputw Unexecuted instantiation: kstring.c:kputw Unexecuted instantiation: bgzf.c:kputw Unexecuted instantiation: faidx.c:kputw Unexecuted instantiation: md5.c:kputw Unexecuted instantiation: tbx.c:kputw Unexecuted instantiation: cram_codecs.c:kputw |
383 | | |
384 | | static inline int kputll(long long c, kstring_t *s) |
385 | 16.6M | { |
386 | | // Worst case expansion. One check reduces function size |
387 | | // and aids inlining chance. Memory overhead is minimal. |
388 | 16.6M | if (ks_resize(s, s->l + 23) < 0) |
389 | 0 | return EOF; |
390 | | |
391 | 16.6M | unsigned long long x = c; |
392 | 16.6M | if (c < 0) { |
393 | 2.32k | x = -x; |
394 | 2.32k | s->s[s->l++] = '-'; |
395 | 2.32k | } |
396 | | |
397 | 16.6M | if (x <= UINT32_MAX) |
398 | 16.6M | return kputuw(x, s); |
399 | | |
400 | 6.35k | static const char kputull_dig2r[] = |
401 | 6.35k | "00010203040506070809" |
402 | 6.35k | "10111213141516171819" |
403 | 6.35k | "20212223242526272829" |
404 | 6.35k | "30313233343536373839" |
405 | 6.35k | "40414243444546474849" |
406 | 6.35k | "50515253545556575859" |
407 | 6.35k | "60616263646566676869" |
408 | 6.35k | "70717273747576777879" |
409 | 6.35k | "80818283848586878889" |
410 | 6.35k | "90919293949596979899"; |
411 | 6.35k | unsigned int l, j; |
412 | 6.35k | char *cp; |
413 | | |
414 | | // Find out how long the number is (could consider clzll) |
415 | 6.35k | uint64_t m = 1; |
416 | 6.35k | l = 0; |
417 | 6.35k | if (sizeof(long long)==sizeof(uint64_t) && x >= 10000000000000000000ULL) { |
418 | | // avoids overflow below |
419 | 0 | l = 20; |
420 | 6.35k | } else { |
421 | 86.2k | do { |
422 | 86.2k | l++; |
423 | 86.2k | m *= 10; |
424 | 86.2k | } while (x >= m); |
425 | 6.35k | } |
426 | | |
427 | | // Add digits two at a time |
428 | 6.35k | j = l; |
429 | 6.35k | cp = s->s + s->l; |
430 | 48.0k | while (x >= 10) { |
431 | 41.7k | const char *d = &kputull_dig2r[2*(x%100)]; |
432 | 41.7k | x /= 100; |
433 | 41.7k | memcpy(&cp[j-=2], d, 2); |
434 | 41.7k | } |
435 | | |
436 | | // Last one (if necessary). We know that x < 10 by now. |
437 | 6.35k | if (j == 1) |
438 | 2.79k | cp[0] = x + '0'; |
439 | | |
440 | 6.35k | s->l += l; |
441 | 6.35k | s->s[s->l] = 0; |
442 | 6.35k | return 0; |
443 | 16.6M | } Unexecuted instantiation: hts_open_fuzzer.c:kputll Unexecuted instantiation: header.c:kputll Unexecuted instantiation: hfile.c:kputll Unexecuted instantiation: hts.c:kputll Unexecuted instantiation: hts_expr.c:kputll Unexecuted instantiation: multipart.c:kputll Unexecuted instantiation: region.c:kputll Line | Count | Source | 385 | 16.5M | { | 386 | | // Worst case expansion. One check reduces function size | 387 | | // and aids inlining chance. Memory overhead is minimal. | 388 | 16.5M | if (ks_resize(s, s->l + 23) < 0) | 389 | 0 | return EOF; | 390 | | | 391 | 16.5M | unsigned long long x = c; | 392 | 16.5M | if (c < 0) { | 393 | 2.32k | x = -x; | 394 | 2.32k | s->s[s->l++] = '-'; | 395 | 2.32k | } | 396 | | | 397 | 16.5M | if (x <= UINT32_MAX) | 398 | 16.5M | return kputuw(x, s); | 399 | | | 400 | 4.28k | static const char kputull_dig2r[] = | 401 | 4.28k | "00010203040506070809" | 402 | 4.28k | "10111213141516171819" | 403 | 4.28k | "20212223242526272829" | 404 | 4.28k | "30313233343536373839" | 405 | 4.28k | "40414243444546474849" | 406 | 4.28k | "50515253545556575859" | 407 | 4.28k | "60616263646566676869" | 408 | 4.28k | "70717273747576777879" | 409 | 4.28k | "80818283848586878889" | 410 | 4.28k | "90919293949596979899"; | 411 | 4.28k | unsigned int l, j; | 412 | 4.28k | char *cp; | 413 | | | 414 | | // Find out how long the number is (could consider clzll) | 415 | 4.28k | uint64_t m = 1; | 416 | 4.28k | l = 0; | 417 | 4.28k | if (sizeof(long long)==sizeof(uint64_t) && x >= 10000000000000000000ULL) { | 418 | | // avoids overflow below | 419 | 0 | l = 20; | 420 | 4.28k | } else { | 421 | 57.1k | do { | 422 | 57.1k | l++; | 423 | 57.1k | m *= 10; | 424 | 57.1k | } while (x >= m); | 425 | 4.28k | } | 426 | | | 427 | | // Add digits two at a time | 428 | 4.28k | j = l; | 429 | 4.28k | cp = s->s + s->l; | 430 | 32.1k | while (x >= 10) { | 431 | 27.8k | const char *d = &kputull_dig2r[2*(x%100)]; | 432 | 27.8k | x /= 100; | 433 | 27.8k | memcpy(&cp[j-=2], d, 2); | 434 | 27.8k | } | 435 | | | 436 | | // Last one (if necessary). We know that x < 10 by now. | 437 | 4.28k | if (j == 1) | 438 | 1.36k | cp[0] = x + '0'; | 439 | | | 440 | 4.28k | s->l += l; | 441 | 4.28k | s->s[s->l] = 0; | 442 | 4.28k | return 0; | 443 | 16.5M | } |
Unexecuted instantiation: sam_mods.c:kputll Unexecuted instantiation: simd.c:kputll Unexecuted instantiation: textutils.c:kputll Line | Count | Source | 385 | 35.9k | { | 386 | | // Worst case expansion. One check reduces function size | 387 | | // and aids inlining chance. Memory overhead is minimal. | 388 | 35.9k | if (ks_resize(s, s->l + 23) < 0) | 389 | 0 | return EOF; | 390 | | | 391 | 35.9k | unsigned long long x = c; | 392 | 35.9k | if (c < 0) { | 393 | 0 | x = -x; | 394 | 0 | s->s[s->l++] = '-'; | 395 | 0 | } | 396 | | | 397 | 35.9k | if (x <= UINT32_MAX) | 398 | 33.9k | return kputuw(x, s); | 399 | | | 400 | 2.07k | static const char kputull_dig2r[] = | 401 | 2.07k | "00010203040506070809" | 402 | 2.07k | "10111213141516171819" | 403 | 2.07k | "20212223242526272829" | 404 | 2.07k | "30313233343536373839" | 405 | 2.07k | "40414243444546474849" | 406 | 2.07k | "50515253545556575859" | 407 | 2.07k | "60616263646566676869" | 408 | 2.07k | "70717273747576777879" | 409 | 2.07k | "80818283848586878889" | 410 | 2.07k | "90919293949596979899"; | 411 | 2.07k | unsigned int l, j; | 412 | 2.07k | char *cp; | 413 | | | 414 | | // Find out how long the number is (could consider clzll) | 415 | 2.07k | uint64_t m = 1; | 416 | 2.07k | l = 0; | 417 | 2.07k | if (sizeof(long long)==sizeof(uint64_t) && x >= 10000000000000000000ULL) { | 418 | | // avoids overflow below | 419 | 0 | l = 20; | 420 | 2.07k | } else { | 421 | 29.0k | do { | 422 | 29.0k | l++; | 423 | 29.0k | m *= 10; | 424 | 29.0k | } while (x >= m); | 425 | 2.07k | } | 426 | | | 427 | | // Add digits two at a time | 428 | 2.07k | j = l; | 429 | 2.07k | cp = s->s + s->l; | 430 | 15.8k | while (x >= 10) { | 431 | 13.8k | const char *d = &kputull_dig2r[2*(x%100)]; | 432 | 13.8k | x /= 100; | 433 | 13.8k | memcpy(&cp[j-=2], d, 2); | 434 | 13.8k | } | 435 | | | 436 | | // Last one (if necessary). We know that x < 10 by now. | 437 | 2.07k | if (j == 1) | 438 | 1.43k | cp[0] = x + '0'; | 439 | | | 440 | 2.07k | s->l += l; | 441 | 2.07k | s->s[s->l] = 0; | 442 | 2.07k | return 0; | 443 | 35.9k | } |
Unexecuted instantiation: cram_decode.c:kputll Unexecuted instantiation: cram_encode.c:kputll Unexecuted instantiation: cram_index.c:kputll Unexecuted instantiation: cram_io.c:kputll Unexecuted instantiation: cram_stats.c:kputll Unexecuted instantiation: open_trace_file.c:kputll Unexecuted instantiation: hfile_libcurl.c:kputll Unexecuted instantiation: hfile_gcs.c:kputll Unexecuted instantiation: hfile_s3.c:kputll Unexecuted instantiation: kstring.c:kputll Unexecuted instantiation: bgzf.c:kputll Unexecuted instantiation: faidx.c:kputll Unexecuted instantiation: md5.c:kputll Unexecuted instantiation: tbx.c:kputll Unexecuted instantiation: cram_codecs.c:kputll |
444 | | |
445 | 0 | static inline int kputl(long c, kstring_t *s) { |
446 | 0 | return kputll(c, s); |
447 | 0 | } Unexecuted instantiation: hts_open_fuzzer.c:kputl Unexecuted instantiation: header.c:kputl Unexecuted instantiation: hfile.c:kputl Unexecuted instantiation: hts.c:kputl Unexecuted instantiation: hts_expr.c:kputl Unexecuted instantiation: multipart.c:kputl Unexecuted instantiation: region.c:kputl Unexecuted instantiation: sam.c:kputl Unexecuted instantiation: sam_mods.c:kputl Unexecuted instantiation: simd.c:kputl Unexecuted instantiation: textutils.c:kputl Unexecuted instantiation: vcf.c:kputl Unexecuted instantiation: cram_decode.c:kputl Unexecuted instantiation: cram_encode.c:kputl Unexecuted instantiation: cram_index.c:kputl Unexecuted instantiation: cram_io.c:kputl Unexecuted instantiation: cram_stats.c:kputl Unexecuted instantiation: open_trace_file.c:kputl Unexecuted instantiation: hfile_libcurl.c:kputl Unexecuted instantiation: hfile_gcs.c:kputl Unexecuted instantiation: hfile_s3.c:kputl Unexecuted instantiation: kstring.c:kputl Unexecuted instantiation: bgzf.c:kputl Unexecuted instantiation: faidx.c:kputl Unexecuted instantiation: md5.c:kputl Unexecuted instantiation: tbx.c:kputl Unexecuted instantiation: cram_codecs.c:kputl |
448 | | |
449 | | /* |
450 | | * Returns 's' split by delimiter, with *n being the number of components; |
451 | | * NULL on failure. |
452 | | */ |
453 | | static inline int *ksplit(kstring_t *s, int delimiter, int *n) |
454 | 0 | { |
455 | 0 | int max = 0, *offsets = 0; |
456 | 0 | *n = ksplit_core(s->s, delimiter, &max, &offsets); |
457 | 0 | return offsets; |
458 | 0 | } Unexecuted instantiation: hts_open_fuzzer.c:ksplit Unexecuted instantiation: header.c:ksplit Unexecuted instantiation: hfile.c:ksplit Unexecuted instantiation: hts.c:ksplit Unexecuted instantiation: hts_expr.c:ksplit Unexecuted instantiation: multipart.c:ksplit Unexecuted instantiation: region.c:ksplit Unexecuted instantiation: sam.c:ksplit Unexecuted instantiation: sam_mods.c:ksplit Unexecuted instantiation: simd.c:ksplit Unexecuted instantiation: textutils.c:ksplit Unexecuted instantiation: vcf.c:ksplit Unexecuted instantiation: cram_decode.c:ksplit Unexecuted instantiation: cram_encode.c:ksplit Unexecuted instantiation: cram_index.c:ksplit Unexecuted instantiation: cram_io.c:ksplit Unexecuted instantiation: cram_stats.c:ksplit Unexecuted instantiation: open_trace_file.c:ksplit Unexecuted instantiation: hfile_libcurl.c:ksplit Unexecuted instantiation: hfile_gcs.c:ksplit Unexecuted instantiation: hfile_s3.c:ksplit Unexecuted instantiation: kstring.c:ksplit Unexecuted instantiation: bgzf.c:ksplit Unexecuted instantiation: faidx.c:ksplit Unexecuted instantiation: md5.c:ksplit Unexecuted instantiation: tbx.c:ksplit Unexecuted instantiation: cram_codecs.c:ksplit |
459 | | |
460 | | /** |
461 | | * kinsert_char - inserts a char to kstring |
462 | | * @param c - char to insert |
463 | | * @param pos - position at which to insert, starting from 0 |
464 | | * @param s - pointer to output string |
465 | | * Returns 0 on success and -1 on failure |
466 | | * 0 for pos inserts at start and length of current string as pos appends at |
467 | | * the end. |
468 | | */ |
469 | | static inline int kinsert_char(char c, size_t pos, kstring_t *s) |
470 | 905 | { |
471 | 905 | if (!s || pos > s->l) { |
472 | 0 | return EOF; |
473 | 0 | } |
474 | 905 | if (ks_resize(s, s->l + 2) < 0) { |
475 | 0 | return EOF; |
476 | 0 | } |
477 | 905 | memmove(s->s + pos + 1, s->s + pos, s->l - pos); |
478 | 905 | s->s[pos] = c; |
479 | 905 | s->s[++s->l] = 0; |
480 | 905 | return 0; |
481 | 905 | } Unexecuted instantiation: hts_open_fuzzer.c:kinsert_char Unexecuted instantiation: header.c:kinsert_char Unexecuted instantiation: hfile.c:kinsert_char Unexecuted instantiation: hts.c:kinsert_char Unexecuted instantiation: hts_expr.c:kinsert_char Unexecuted instantiation: multipart.c:kinsert_char Unexecuted instantiation: region.c:kinsert_char Unexecuted instantiation: sam.c:kinsert_char Unexecuted instantiation: sam_mods.c:kinsert_char Unexecuted instantiation: simd.c:kinsert_char Unexecuted instantiation: textutils.c:kinsert_char Line | Count | Source | 470 | 905 | { | 471 | 905 | if (!s || pos > s->l) { | 472 | 0 | return EOF; | 473 | 0 | } | 474 | 905 | if (ks_resize(s, s->l + 2) < 0) { | 475 | 0 | return EOF; | 476 | 0 | } | 477 | 905 | memmove(s->s + pos + 1, s->s + pos, s->l - pos); | 478 | 905 | s->s[pos] = c; | 479 | 905 | s->s[++s->l] = 0; | 480 | 905 | return 0; | 481 | 905 | } |
Unexecuted instantiation: cram_decode.c:kinsert_char Unexecuted instantiation: cram_encode.c:kinsert_char Unexecuted instantiation: cram_index.c:kinsert_char Unexecuted instantiation: cram_io.c:kinsert_char Unexecuted instantiation: cram_stats.c:kinsert_char Unexecuted instantiation: open_trace_file.c:kinsert_char Unexecuted instantiation: hfile_libcurl.c:kinsert_char Unexecuted instantiation: hfile_gcs.c:kinsert_char Unexecuted instantiation: hfile_s3.c:kinsert_char Unexecuted instantiation: kstring.c:kinsert_char Unexecuted instantiation: bgzf.c:kinsert_char Unexecuted instantiation: faidx.c:kinsert_char Unexecuted instantiation: md5.c:kinsert_char Unexecuted instantiation: tbx.c:kinsert_char Unexecuted instantiation: cram_codecs.c:kinsert_char |
482 | | |
483 | | /** |
484 | | * kinsert_str - inserts a null terminated string to kstring |
485 | | * @param str - string to insert |
486 | | * @param pos - position at which to insert, starting from 0 |
487 | | * @param s - pointer to output string |
488 | | * Returns 0 on success and -1 on failure |
489 | | * 0 for pos inserts at start and length of current string as pos appends at |
490 | | * the end. empty string makes no update. |
491 | | */ |
492 | | static inline int kinsert_str(const char *str, size_t pos, kstring_t *s) |
493 | 0 | { |
494 | 0 | size_t len = 0; |
495 | 0 | if (!s || pos > s->l || !str) { |
496 | 0 | return EOF; |
497 | 0 | } |
498 | 0 | if (!(len = strlen(str))) { |
499 | 0 | return 0; |
500 | 0 | } |
501 | 0 | if (ks_resize(s, s->l + len + 1) < 0) { |
502 | 0 | return EOF; |
503 | 0 | } |
504 | 0 | memmove(s->s + pos + len, s->s + pos, s->l - pos); |
505 | 0 | memcpy(s->s + pos, str, len); |
506 | 0 | s->l += len; |
507 | 0 | s->s[s->l] = '\0'; |
508 | 0 | return 0; |
509 | 0 | } Unexecuted instantiation: hts_open_fuzzer.c:kinsert_str Unexecuted instantiation: header.c:kinsert_str Unexecuted instantiation: hfile.c:kinsert_str Unexecuted instantiation: hts.c:kinsert_str Unexecuted instantiation: hts_expr.c:kinsert_str Unexecuted instantiation: multipart.c:kinsert_str Unexecuted instantiation: region.c:kinsert_str Unexecuted instantiation: sam.c:kinsert_str Unexecuted instantiation: sam_mods.c:kinsert_str Unexecuted instantiation: simd.c:kinsert_str Unexecuted instantiation: textutils.c:kinsert_str Unexecuted instantiation: vcf.c:kinsert_str Unexecuted instantiation: cram_decode.c:kinsert_str Unexecuted instantiation: cram_encode.c:kinsert_str Unexecuted instantiation: cram_index.c:kinsert_str Unexecuted instantiation: cram_io.c:kinsert_str Unexecuted instantiation: cram_stats.c:kinsert_str Unexecuted instantiation: open_trace_file.c:kinsert_str Unexecuted instantiation: hfile_libcurl.c:kinsert_str Unexecuted instantiation: hfile_gcs.c:kinsert_str Unexecuted instantiation: hfile_s3.c:kinsert_str Unexecuted instantiation: kstring.c:kinsert_str Unexecuted instantiation: bgzf.c:kinsert_str Unexecuted instantiation: faidx.c:kinsert_str Unexecuted instantiation: md5.c:kinsert_str Unexecuted instantiation: tbx.c:kinsert_str Unexecuted instantiation: cram_codecs.c:kinsert_str |
510 | | |
511 | | #ifdef HTSLIB_SSIZE_T |
512 | | #undef HTSLIB_SSIZE_T |
513 | | #undef ssize_t |
514 | | #endif |
515 | | |
516 | | #ifdef HTSLIB_EOVERFLOW |
517 | | #undef HTSLIB_EOVERFLOW |
518 | | #undef EOVERFLOW |
519 | | #endif |
520 | | |
521 | | #endif |