Impementation-dependent casts from uchar to char

Marijn Kruisselbrink mkruisselbrink at kde.org
Wed Jan 2 23:04:33 GMT 2013


On Wed, Jan 2, 2013 at 2:50 PM, Jaroslaw Staniek <staniek at kde.org> wrote:

> On 2 January 2013 22:52, Marijn Kruisselbrink <mkruisselbrink at kde.org>
> wrote:
> > On Wed, Jan 2, 2013 at 1:26 PM, Jaroslaw Staniek <staniek at kde.org>
> wrote:
> >>
> >> Hello Marijn,
> >> There are impementation-dependent casts from uchar to char:
> >
> > Ah yes, that is indeed not good.
> >
> >> Since this is your code, could you point me what are these values?
> >
> > I assume I copied these values from whatever document documents the
> > encryption ms office uses... Not sure what the nicest way is to hardcode
> > binary data in c++ source code... "\xfe\xa7\xd2\x76\x3b\x4b\x9e\x79"
> might
> > work, but has the downside that there is a trailing 0 byte that should
> not
> > be included in the qbytearray. Signed char constants seem ugly, since
> > QByteArray expects regular char, not signed char (although I guess it
> would
> > be safe, since the signed->unsigned underflowing conversion is defined
> > unlike this unsigned->signed overflow).
>
> It's implementaton defined:
> http://c0x.coding-guidelines.com/6.4.4.4.html#891
>
> How about this, similarly safe only when sizeof(char)==1 but warnings
> disappear:
>
sizeof(char) is always 1, so yes, that looks good to me (if you replace
sizeof(char) with 1).


>
> -            const char blockKeyData1[] = {0xfe, 0xa7, 0xd2, 0x76,
> 0x3b, 0x4b, 0x9e, 0x79};
> -            QByteArray blockKey1(blockKeyData1, sizeof(blockKeyData1));
> +            const char blockKeyData1[] =
> "\xfe\xa7\xd2\x76\x3b\x4b\x9e\x79";
> +            QByteArray blockKey1(blockKeyData1, sizeof(blockKeyData1)
> - sizeof(char));
>
> --
> regards / pozdrawiam, Jaroslaw Staniek
>  Kexi & Calligra & KDE | http://calligra.org/kexi | http://kde.org
>  Qt Certified Specialist | http://qt-project.org
>  http://www.linkedin.com/in/jstaniek
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/calligra-devel/attachments/20130102/bf740e72/attachment.htm>


More information about the calligra-devel mailing list