I've hit an interesting problem. This is on fdbsd13/arm64/rpi4, and
there's something amiss with char to int conversions. Or at least, a difference from i386.
The immediate symptom is that spfmilter won't start - just says
'unrecognised option', with a seemingly empty string appended that's
actually 0xFF.
This comes from the getopt() loop, whose guts are
char c;
while ( ( c = getopt_long( argc, argv, shortopts, longopts, &idx ) ) !=
-1 ) {
.....
I've hit an interesting problem. This is on fdbsd13/arm64/rpi4, and
there's something amiss with char to int conversions. Or at least, a difference from i386.
char c;
while ( ( c = getopt_long( argc, argv, shortopts, longopts, &idx ) ) !=
-1 ) {
On 2022-01-31, Mike Scott <usenet.16@scottsonline.org.uk.invalid> wrote:
I've hit an interesting problem. This is on fdbsd13/arm64/rpi4, and
there's something amiss with char to int conversions. Or at least, a
difference from i386.
On arm64, plain "char" is "unsigned char". On x86 it's "signed char".
char c;
while ( ( c = getopt_long( argc, argv, shortopts, longopts, &idx ) ) !=
-1 ) {
That's broken code. It must be "int c". Only an int will capture
all possible char values and additionally -1.
The prototypical example is this:
while ((c = getchar()) != EOF) { /* EOF is -1 */
...
}
With "char c" this is broken for both platforms:
* On arm64 it's an infinite loop.
* On x86 it will prematurely terminate when it encounters a byte
with the value 0xff.
Any variable that is intended to hold any character plus EOF _must_
be declared int. This is basic C.
Most architectures default to signed char. Notably arm and powerpc,
in their 32 and 64-bit incarnations, default to unsigned.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (2 / 14) |
Uptime: | 64:34:40 |
Calls: | 8,354 |
Calls today: | 14 |
Files: | 13,159 |
Messages: | 5,893,806 |
Posted today: | 1 |