Skip to content

Commit

Permalink
Avoid 'z' format with MSVCRT (#1559)
Browse files Browse the repository at this point in the history
### Issues:
* aws/aws-lc-rs#413

### Description of changes: 
* Some versions of MinGW complain about use of `z` in a format
specification:
https://stackoverflow.com/questions/44382862/how-to-printf-a-size-t-without-warning-in-mingw-w64-gcc-7-1
* This problem relates to a claim that the Windows C-Runtime ("msvcrt")
only supports C89 format strings. However, this appears to have been
addressed by (or before) MSVC 2015:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-140#size-prefixes-for-printf-and-wprintf-format-type-specifiers

### Testing:
With this change I was able to successfully cross-compile to
x86_64-pc-windows-gnu:
```
❯ cross build -p aws-lc-rs --features bindgen --target x86_64-pc-windows-gnu
...
   Compiling aws-lc-sys v0.16.0 (/Users/justsmth/repos/aws-lc-rs/aws-lc-sys)
warning: [email protected]: Generating bindings - internal bindgen. Platform: x86_64-pc-windows-gnu
   Compiling aws-lc-rs v1.7.1 (/Users/justsmth/repos/aws-lc-rs/aws-lc-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 29.94s
```

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
  • Loading branch information
justsmth authored Apr 29, 2024
1 parent c25dc2a commit 2ea6706
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crypto/asn1/a_mbstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,22 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
utf8_len += cbb_get_utf8_len(c);
if (maxsize > 0 && nchar > (size_t)maxsize) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
#if defined(OPENSSL_WINDOWS)
ERR_add_error_dataf("maxsize=%lu", (unsigned long)maxsize);
#else
ERR_add_error_dataf("maxsize=%zu", (size_t)maxsize);
#endif
return -1;
}
}

if (minsize > 0 && nchar < (size_t)minsize) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
#if defined(OPENSSL_WINDOWS)
ERR_add_error_dataf("minsize=%lu", (unsigned long)minsize);
#else
ERR_add_error_dataf("minsize=%zu", (size_t)minsize);
#endif
return -1;
}

Expand Down

0 comments on commit 2ea6706

Please sign in to comment.