various changes to make clang not give warnings

cute-signatures
Timo Teräs 2020-10-07 21:16:13 +03:00
parent 90137499af
commit 5f66b618ef
5 changed files with 19 additions and 14 deletions

View File

@ -351,8 +351,9 @@ static int parse_options(int argc, char **argv, struct apk_applet *applet, void
if ((unsigned char)*d >= 0xf0) if ((unsigned char)*d >= 0xf0)
num_short = *d++ & 0x0f; num_short = *d++ & 0x0f;
for (; num_short > 0; num_short--) { for (; num_short > 0; num_short--) {
assert(*d >= 64 && *d < 128); unsigned char ch = *(unsigned char *)d;
short_option_val[*d - 64] = opt->val; assert(ch >= 64 && ch < 128);
short_option_val[ch-64] = opt->val;
*sopt++ = *d++; *sopt++ = *d++;
if (opt->has_arg != no_argument) if (opt->has_arg != no_argument)
*sopt++ = ':'; *sopt++ = ':';
@ -381,13 +382,6 @@ static int parse_options(int argc, char **argv, struct apk_applet *applet, void
if (help_requested || r == -ENOTSUP) if (help_requested || r == -ENOTSUP)
return usage(applet); return usage(applet);
if (applet == NULL) {
if (argc > 1) {
apk_error("'%s' is not an apk command. See 'apk --help'.", argv[1]);
return 1;
}
return usage(NULL);
}
return 0; return 0;
} }
@ -497,6 +491,14 @@ int main(int argc, char **argv)
r = parse_options(argc, argv, applet, ctx, &dbopts); r = parse_options(argc, argv, applet, ctx, &dbopts);
if (r != 0) goto err; if (r != 0) goto err;
if (applet == NULL) {
if (argc > 1) {
apk_error("'%s' is not an apk command. See 'apk --help'.", argv[1]);
return 1;
}
return usage(NULL);
}
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc >= 1 && strcmp(argv[0], applet->name) == 0) { if (argc >= 1 && strcmp(argv[0], applet->name) == 0) {

View File

@ -7,6 +7,7 @@
* SPDX-License-Identifier: GPL-2.0-only * SPDX-License-Identifier: GPL-2.0-only
*/ */
#include <assert.h>
#include <limits.h> #include <limits.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
@ -264,6 +265,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
off_t humanized, size_diff = 0; off_t humanized, size_diff = 0;
int r, errors = 0; int r, errors = 0;
assert(world);
if (apk_db_check_world(db, world) != 0) { if (apk_db_check_world(db, world) != 0) {
apk_error("Not committing changes due to missing repository tags. " apk_error("Not committing changes due to missing repository tags. "
"Use --force-broken-world to override."); "Use --force-broken-world to override.");

View File

@ -2406,6 +2406,7 @@ static int apk_db_install_archive_entry(void *_ctx,
const struct apk_file_info *ae, const struct apk_file_info *ae,
struct apk_istream *is) struct apk_istream *is)
{ {
static const char dot1[] = "/./", dot2[] = "/../";
struct install_ctx *ctx = (struct install_ctx *) _ctx; struct install_ctx *ctx = (struct install_ctx *) _ctx;
struct apk_database *db = ctx->db; struct apk_database *db = ctx->db;
struct apk_package *pkg = ctx->pkg, *opkg; struct apk_package *pkg = ctx->pkg, *opkg;
@ -2448,10 +2449,9 @@ static int apk_db_install_archive_entry(void *_ctx,
/* Sanity check the file name */ /* Sanity check the file name */
if (ae->name[0] == '/' || if (ae->name[0] == '/' ||
strncmp(ae->name, "/./"+1, 3) == 0 || strncmp(ae->name, &dot1[1], 2) == 0 ||
strncmp(ae->name, "/../"+1, 3) == 0 || strncmp(ae->name, &dot2[1], 3) == 0 ||
strstr(ae->name, "/./") || strstr(ae->name, dot1) || strstr(ae->name, dot2)) {
strstr(ae->name, "/../")) {
apk_warning(PKG_VER_FMT": ignoring malicious file %s", apk_warning(PKG_VER_FMT": ignoring malicious file %s",
PKG_VER_PRINTF(pkg), ae->name); PKG_VER_PRINTF(pkg), ae->name);
ipkg->broken_files = 1; ipkg->broken_files = 1;

View File

@ -37,6 +37,7 @@ static int gzi_boundary_change(struct apk_gzip_istream *gis)
{ {
int r; int r;
if (!gis->cb) return 0;
r = gis->cb(gis->cbctx, gis->is.err ? APK_MPART_END : APK_MPART_BOUNDARY, gis->cbarg); r = gis->cb(gis->cbctx, gis->is.err ? APK_MPART_END : APK_MPART_BOUNDARY, gis->cbarg);
if (r > 0) r = -ECANCELED; if (r > 0) r = -ECANCELED;
if (r != 0) gis->is.err = r; if (r != 0) gis->is.err = r;

View File

@ -488,7 +488,7 @@ void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action,
ctx->md = EVP_sha1(); ctx->md = EVP_sha1();
break; break;
default: default:
action = APK_SIGN_NONE; ctx->action = APK_SIGN_NONE;
ctx->md = EVP_md_null(); ctx->md = EVP_md_null();
ctx->control_started = 1; ctx->control_started = 1;
ctx->data_started = 1; ctx->data_started = 1;