| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: check-portability.c,v 1.9 2020/03/13 16:43:05 rillig Exp $ */ | | 1 | /* $NetBSD: check-portability.c,v 1.10 2020/03/14 09:18:49 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | Copyright (c) 2020 Roland Illig | | 4 | Copyright (c) 2020 Roland Illig |
5 | All rights reserved. | | 5 | All rights reserved. |
6 | | | 6 | |
7 | Redistribution and use in source and binary forms, with or without | | 7 | Redistribution and use in source and binary forms, with or without |
8 | modification, are permitted provided that the following conditions | | 8 | modification, are permitted provided that the following conditions |
9 | are met: | | 9 | are met: |
10 | | | 10 | |
11 | 1. Redistributions of source code must retain the above copyright | | 11 | 1. Redistributions of source code must retain the above copyright |
12 | notice, this list of conditions and the following disclaimer. | | 12 | notice, this list of conditions and the following disclaimer. |
13 | 2. Redistributions in binary form must reproduce the above copyright | | 13 | 2. Redistributions in binary form must reproduce the above copyright |
14 | notice, this list of conditions and the following disclaimer in the | | 14 | notice, this list of conditions and the following disclaimer in the |
| @@ -161,28 +161,27 @@ cstr_right_of_last(cstr s, cstr delimite | | | @@ -161,28 +161,27 @@ cstr_right_of_last(cstr s, cstr delimite |
161 | | | 161 | |
162 | // str is a modifiable string buffer. | | 162 | // str is a modifiable string buffer. |
163 | typedef struct { | | 163 | typedef struct { |
164 | char *data; | | 164 | char *data; |
165 | size_t len; | | 165 | size_t len; |
166 | size_t cap; | | 166 | size_t cap; |
167 | } str; | | 167 | } str; |
168 | | | 168 | |
169 | #define STR_EMPTY { nullptr, 0, 0 } | | 169 | #define STR_EMPTY { nullptr, 0, 0 } |
170 | | | 170 | |
171 | static cstr | | 171 | static cstr |
172 | str_c(str *s) | | 172 | str_c(str *s) |
173 | { | | 173 | { |
174 | assert(s->data != nullptr); | | 174 | return (cstr) { s->data == nullptr ? "" : s->data, s->len }; |
175 | return (cstr) { s->data, s->len }; | | | |
176 | } | | 175 | } |
177 | | | 176 | |
178 | static void | | 177 | static void |
179 | str_free(str *s) | | 178 | str_free(str *s) |
180 | { | | 179 | { |
181 | free(s->data); | | 180 | free(s->data); |
182 | } | | 181 | } |
183 | | | 182 | |
184 | static void | | 183 | static void |
185 | str_reserve(str *s, size_t n) | | 184 | str_reserve(str *s, size_t n) |
186 | { | | 185 | { |
187 | size_t req_len = s->len + n; | | 186 | size_t req_len = s->len + n; |
188 | assert(req_len >= s->len); | | 187 | assert(req_len >= s->len); |