Skip to content

Commit 57e194e

Browse files
committed
Fix compile error in Windows CI job caused by 0779950
In 6fc8d01, pakutoma added some additional validation logic to mb_detect_encoding. Since the implementation of mb_detect_encoding has changed significantly between PHP 8.2 and 8.3, when merging this change down from PHP-8.2 into master, I had to port his code over to the new implementation in master. However, I did this in a wrong way. In merge commit 0779950, the ported code modifies a function argument (to mb_guess_encoding) which is marked 'const'. In the Windows CI job, MS VC++ rightly flags this as a compile error. Adjust the code to accomplish the same thing, but without destructively modifying 'const' arguments.
1 parent 345abce commit 57e194e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

ext/mbstring/mbstring.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,18 +3001,6 @@ static const mbfl_encoding* mb_guess_encoding(unsigned char *in, size_t in_len,
30013001
return *elist;
30023002
}
30033003

3004-
/* If any candidate encoding have specialized validation functions, use those first
3005-
* to eliminate as many candidates as possible */
3006-
if (strict) {
3007-
for (unsigned int i = 0; i < elist_size; i++) {
3008-
if (elist[i]->check != NULL && !elist[i]->check(in, in_len)) {
3009-
elist_size--;
3010-
memmove(&elist[i], &elist[i+1], (elist_size - i) * sizeof(mbfl_encoding*));
3011-
i--;
3012-
}
3013-
}
3014-
}
3015-
30163004
uint32_t wchar_buf[128];
30173005
struct conversion_data {
30183006
const mbfl_encoding *enc;
@@ -3050,6 +3038,19 @@ static const mbfl_encoding* mb_guess_encoding(unsigned char *in, size_t in_len,
30503038
}
30513039
}
30523040

3041+
/* If any candidate encodings have specialized validation functions, use them
3042+
* to eliminate as many candidates as possible */
3043+
if (strict) {
3044+
for (unsigned int i = 0; i < elist_size; i++) {
3045+
const mbfl_encoding *enc = data[i].enc;
3046+
if (enc->check != NULL && !enc->check(in, in_len)) {
3047+
elist_size--;
3048+
memmove(&data[i], &data[i+1], (elist_size - i) * sizeof(struct conversion_data));
3049+
i--;
3050+
}
3051+
}
3052+
}
3053+
30533054
unsigned int finished = 0; /* For how many candidate encodings have we processed all the input? */
30543055
while (elist_size > 1 && finished < elist_size) {
30553056
unsigned int i = 0;

0 commit comments

Comments
 (0)