@@ -183,20 +183,20 @@ ly_getutf8(const char **input, uint32_t *utf8_char, size_t *bytes_read)
183183 len = 1 ;
184184
185185 if ((c < 0x20 ) && (c != 0x9 ) && (c != 0xa ) && (c != 0xd )) {
186- return LY_EINVAL ;
186+ goto error ;
187187 }
188188 } else if ((c & 0xe0 ) == 0xc0 ) {
189189 /* two bytes character */
190190 len = 2 ;
191191
192192 aux = (* input )[1 ];
193193 if ((aux & 0xc0 ) != 0x80 ) {
194- return LY_EINVAL ;
194+ goto error ;
195195 }
196196 c = ((c & 0x1f ) << 6 ) | (aux & 0x3f );
197197
198198 if (c < 0x80 ) {
199- return LY_EINVAL ;
199+ goto error ;
200200 }
201201 } else if ((c & 0xf0 ) == 0xe0 ) {
202202 /* three bytes character */
@@ -206,14 +206,14 @@ ly_getutf8(const char **input, uint32_t *utf8_char, size_t *bytes_read)
206206 for (uint64_t i = 1 ; i <= 2 ; i ++ ) {
207207 aux = (* input )[i ];
208208 if ((aux & 0xc0 ) != 0x80 ) {
209- return LY_EINVAL ;
209+ goto error ;
210210 }
211211
212212 c = (c << 6 ) | (aux & 0x3f );
213213 }
214214
215215 if ((c < 0x800 ) || ((c > 0xd7ff ) && (c < 0xe000 )) || (c > 0xfffd )) {
216- return LY_EINVAL ;
216+ goto error ;
217217 }
218218 } else if ((c & 0xf8 ) == 0xf0 ) {
219219 /* four bytes character */
@@ -223,20 +223,17 @@ ly_getutf8(const char **input, uint32_t *utf8_char, size_t *bytes_read)
223223 for (uint64_t i = 1 ; i <= 3 ; i ++ ) {
224224 aux = (* input )[i ];
225225 if ((aux & 0xc0 ) != 0x80 ) {
226- return LY_EINVAL ;
226+ goto error ;
227227 }
228228
229229 c = (c << 6 ) | (aux & 0x3f );
230230 }
231231
232232 if ((c < 0x1000 ) || (c > 0x10ffff )) {
233- return LY_EINVAL ;
233+ goto error ;
234234 }
235235 } else {
236- if (bytes_read ) {
237- (* bytes_read ) = 0 ;
238- }
239- return LY_EINVAL ;
236+ goto error ;
240237 }
241238
242239 (* utf8_char ) = c ;
@@ -245,6 +242,12 @@ ly_getutf8(const char **input, uint32_t *utf8_char, size_t *bytes_read)
245242 (* bytes_read ) = len ;
246243 }
247244 return LY_SUCCESS ;
245+
246+ error :
247+ if (bytes_read ) {
248+ (* bytes_read ) = 0 ;
249+ }
250+ return LY_EINVAL ;
248251}
249252
250253/**
0 commit comments