X-Git-Url: https://git.draconx.ca/gitweb/upkg.git/blobdiff_plain/101802f109713394c6c8e0daea8129c6ee3c60d0..5fca0fe6cdbe90d31cce2ef17c1d76a8cfe0f921:/src/libupkg.c diff --git a/src/libupkg.c b/src/libupkg.c index 680faac..3ecce7f 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -1,6 +1,6 @@ /* * upkg: tool for manipulating Unreal Tournament packages. - * Copyright (C) 2009 Nick Bowler + * Copyright © 2009-2011 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,7 +46,7 @@ struct upkg_name { struct upkg_export_priv { struct upkg_export pub; - long package, class, super; + long class, super; unsigned long size, offset; }; @@ -112,10 +112,9 @@ const struct upkg_file_ops upkg_default_fops = { */ size_t upkg_decode_index(long *val, unsigned char *bytes, size_t n) { - size_t i = 0; - *val = 0; - while (i < MIN(n, 5)) { + + for (size_t i = 0; i < MIN(n, 5); i++) { /* * Least significant bytes are first, so we need to do this * nonsense. @@ -127,18 +126,14 @@ size_t upkg_decode_index(long *val, unsigned char *bytes, size_t n) *val += tmp; if (!(bytes[i] & (i == 0 ? 0x40 : 0x80))) { - i++; - break; + if (bytes[0] & 0x80) + *val = -*val; + return i+1; } - - i++; } - if (i > MIN(n, 5) || n == 0) - return 0; - if (bytes[0] & 0x80) - *val = -*val; - return i; + /* Error */ + return 0; } static struct upkg_priv *init_upkg(unsigned char hdr[static UPKG_HDR_SIZE]) @@ -301,7 +296,7 @@ static int pkg_init_exports(struct upkg_priv *pkg) len += rc; if (nbuf-len < 4) goto err; - export->package = unpack_s32_le(buf+len); + export->pub.package = unpack_s32_le(buf+len); len += 4; rc = upkg_decode_index(&tmp, buf+len, nbuf-len); @@ -504,8 +499,9 @@ long upkg_export_find(struct upkg *pub, long parent, const char *name) struct upkg_export_priv *e = &pkg->exports[i]; /* Assertion: an object's package is an export. */ - format_assert(e->package >= 0, continue); - if (e->package == package && strcmp(e->pub.name, name) == 0) { + format_assert(e->pub.package >= 0, continue); + if (e->pub.package == package + && strcmp(e->pub.name, name) == 0) { return i; } }