[OTR-dev] otrl_base64_otr_decode() function...
Justin Ferguson
jnferguson at gmail.com
Wed Jul 18 02:08:39 EDT 2012
deja vu, (also looks like parse.c::decode() has the same construct):
gcry_error_t otrl_proto_data_read_flags(const char *datamsg,
unsigned char *flagsp)
{
char *otrtag, *endtag;
unsigned char *rawmsg = NULL;
unsigned char *bufp;
size_t msglen, rawlen, lenp;
unsigned char version;
if (flagsp) *flagsp = 0;
otrtag = strstr(datamsg, "?OTR:");
if (!otrtag) {
goto invval;
}
endtag = strchr(otrtag, '.');
if (endtag) {
msglen = endtag-otrtag;
} else {
msglen = strlen(otrtag);
}
/* Base64-decode the message */
rawlen = ((msglen-5) / 4) * 3; /* maximum possible */
rawmsg = malloc(rawlen);
if (!rawmsg && rawlen > 0) {
return gcry_error(GPG_ERR_ENOMEM);
}
rawlen = otrl_base64_decode(rawmsg, otrtag+5, msglen-5); /* actual size */
On Tue, Jul 17, 2012 at 2:56 PM, Ian Goldberg <ian at cypherpunks.ca> wrote:
> On Tue, Jul 17, 2012 at 10:39:39PM -0400, Paul Wouters wrote:
>> On Tue, 17 Jul 2012, Ian Goldberg wrote:
>>
>> >@@ -237,7 +237,7 @@ int otrl_base64_otr_decode(const char *msg, unsigned char **
>> > }
>> >
>> > /* Base64-decode the message */
>> >- rawlen = ((msglen-5) / 4) * 3; /* maximum possible */
>> >+ rawlen = ((msglen-5+3) / 4) * 3; /* maximum possible */
>> > rawmsg = malloc(rawlen);
>> > if (!rawmsg && rawlen > 0) {
>> > return -1;
>>
>> Personally, I prefer things like sizeof("===") over literals like '3'.
>
> The "3" is actually "4-1", as the way to write ceil(x/4) in C (with
> integer arithmetic) is (x+3)/4.
>
> - Ian
> _______________________________________________
> OTR-dev mailing list
> OTR-dev at lists.cypherpunks.ca
> http://lists.cypherpunks.ca/mailman/listinfo/otr-dev
More information about the OTR-dev
mailing list