On 2015-04-14 17:41, John Crispin wrote: > hi > > comments inline > > On 13/04/2015 02:34, Luka Perkov wrote: >> The base code has been taken from zstream project which was >> written by Steven Barth. >> >> Signed-off-by: Luka Perkov <[email protected]> >> CC: Steven Barth <[email protected]> >> --- >> --- /dev/null >> +++ b/b64.h >> @@ -0,0 +1,60 @@ >> +/* >> + * Copyright (C) 2011 Steven Barth <[email protected]> >> + * Copyright (C) 2015 Luka Perkov <[email protected]> >> + * >> + * Permission to use, copy, modify, and/or distribute this software for any >> + * purpose with or without fee is hereby granted, provided that the above >> + * copyright notice and this permission notice appear in all copies. >> + * >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. >> + */ >> + >> +#ifndef __LIBUBOX_B64_H >> +#define __LIBUBOX_B64_H >> + >> +#include <stddef.h> >> + >> +static inline int b64_decode_size(const void *in, size_t len) >> +{ >> + const uint8_t *data = (const uint8_t *) in; >> + int ret; >> + >> + if ((len == 0) || (len % 4)) >> + return 0; >> + >> + ret = (len / 4) * 3; >> + >> + if (data[len - 1] == '=') >> + ret--; >> + >> + if (data[len - 2] == '=') >> + ret--; > > the 2 if clauses look redundant and i guess you could solve it with a loop I'd prefer not passing in the input buffer here at all - a tiny overestimation of the decode size doesn't hurt.
- Felix _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
