From 134e03ea2cbc9dc8772593c283f537c53f09fbbe Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 28 Oct 2019 16:08:55 +0100 Subject: openpgp-ffi: Fix returning pgp_tag_t. - Force pgp_tag_t to have a defined size, and return integers of that size from the ffi glue. - This problem did only manifest itself when compiling with opt-level=1. --- openpgp-ffi/include/sequoia/openpgp/types.h | 4 ++++ openpgp-ffi/src/packet/mod.rs | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'openpgp-ffi') diff --git a/openpgp-ffi/include/sequoia/openpgp/types.h b/openpgp-ffi/include/sequoia/openpgp/types.h index d1612a73..d7a8271e 100644 --- a/openpgp-ffi/include/sequoia/openpgp/types.h +++ b/openpgp-ffi/include/sequoia/openpgp/types.h @@ -286,6 +286,10 @@ typedef enum pgp_tag { PGP_TAG_PRIVATE1 = 61, PGP_TAG_PRIVATE2 = 62, PGP_TAG_PRIVATE3 = 63, + + /* Dummy value to make sure the enumeration has a defined size. + Do not use this value. */ + PGP_TAG_FORCE_WIDTH = INT_MAX, } pgp_tag_t; /*/ diff --git a/openpgp-ffi/src/packet/mod.rs b/openpgp-ffi/src/packet/mod.rs index d332da87..7bab6195 100644 --- a/openpgp-ffi/src/packet/mod.rs +++ b/openpgp-ffi/src/packet/mod.rs @@ -55,8 +55,8 @@ pub struct Packet(openpgp::Packet); /// /// [Section 4.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-4.3 #[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" -fn pgp_packet_tag(p: *const Packet) -> u8 { - u8::from(p.ref_raw().tag()) as u8 +fn pgp_packet_tag(p: *const Packet) -> u32 { + u8::from(p.ref_raw().tag()) as u32 } /// Returns the parsed `Packet's` corresponding OpenPGP tag. @@ -67,9 +67,9 @@ fn pgp_packet_tag(p: *const Packet) -> u8 { /// into an `Packet::Unknown`. `tag()` returns `PGP_TAG_SIGNATURE`, /// whereas `kind()` returns `0`. #[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" -fn pgp_packet_kind(p: *const Packet) -> u8 { +fn pgp_packet_kind(p: *const Packet) -> u32 { if let Some(kind) = p.ref_raw().kind() { - kind.into() + u8::from(kind) as u32 } else { 0 } -- cgit v1.2.3