https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103670

--- Comment #2 from Robert M. Münch <robert.muench at saphirion dot com> ---
That's the code snippet. The for(...) loop is where things start to become
strange. 

The thing is, if we use the code from a pure C program, it works. We are using
this code from a Windows DLL which we call via an FFI from an interpreter.
However, omitting any optimization makes it work.


if (pAdapter != NULL) {
  int i = 0;
  int offset = 0;

  // loop for as many bytes as given by the address length
  // sprintf returns num char written, take: out buffer, max size of buffer,
format, ...
  // format: %[flags][width][.precision][size]type
  // .2 = two characters
  // type X = Unsigned hexadecimal integer; uses "ABCDEF"
  // %.2X 

  LOG(" AddressLenth: %i", pAdapter->AddressLength); // MAC-48 = 48 bit, 6
bytes, 6 two char blocks
  LOG(" mac: %.12X", pAdapter->Address);
  for (i = 0; i < pAdapter->AddressLength; i++) {
    LOG(" i: %i offset: %i, AddressLenth: %i", i, offset,
pAdapter->AddressLength);

    // omit outputting the - char for the last byte
    if (i == (pAdapter->AddressLength - 1)) {
      LOG("%s", " finalizing MAC address buidling");
      offset += sprintf_s(MacAddress + offset, MAX_ADAPTER_ADDRESS_LENGTH,
"%02X",pAdapter->Address[i]);
    } else {
      offset += sprintf_s(MacAddress + offset, MAX_ADAPTER_ADDRESS_LENGTH,
"%02X-",pAdapter->Address[i]);
    }
  }

  LOG("<- OK: %s AddressLength: %i", MacAddress, i);
  return MacAddress;
}

Reply via email to