Fix compile error in Windows CI job caused by 0779950768

In 6fc8d014df, 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 0779950768,
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.
This commit is contained in:
Alex Dowad 2023-03-25 06:02:01 +02:00
parent 345abce590
commit 57e194e02d

View file

@ -3001,18 +3001,6 @@ static const mbfl_encoding* mb_guess_encoding(unsigned char *in, size_t in_len,
return *elist;
}
/* If any candidate encoding have specialized validation functions, use those first
* to eliminate as many candidates as possible */
if (strict) {
for (unsigned int i = 0; i < elist_size; i++) {
if (elist[i]->check != NULL && !elist[i]->check(in, in_len)) {
elist_size--;
memmove(&elist[i], &elist[i+1], (elist_size - i) * sizeof(mbfl_encoding*));
i--;
}
}
}
uint32_t wchar_buf[128];
struct conversion_data {
const mbfl_encoding *enc;
@ -3050,6 +3038,19 @@ static const mbfl_encoding* mb_guess_encoding(unsigned char *in, size_t in_len,
}
}
/* If any candidate encodings have specialized validation functions, use them
* to eliminate as many candidates as possible */
if (strict) {
for (unsigned int i = 0; i < elist_size; i++) {
const mbfl_encoding *enc = data[i].enc;
if (enc->check != NULL && !enc->check(in, in_len)) {
elist_size--;
memmove(&data[i], &data[i+1], (elist_size - i) * sizeof(struct conversion_data));
i--;
}
}
}
unsigned int finished = 0; /* For how many candidate encodings have we processed all the input? */
while (elist_size > 1 && finished < elist_size) {
unsigned int i = 0;