summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@linbit.com>2012-10-04 12:33:09 +0200
committerJavier Jardón <jjardon@gnome.org>2014-09-18 16:29:11 +0100
commit9875fd1e1e47e970f4501303b879644a93ab835a (patch)
treeacdba363eb4f56dc890b86672bd72600fe29da9c
parentbbb840edca64d55de2972fd64c2a097fa3adba41 (diff)
downloadpatch-9875fd1e1e47e970f4501303b879644a93ab835a.tar.gz
Initialize data structures early enough
* src/patch.c (main): Initialize data structures early enough, before error paths can access them. * tests/bad-usage: Test bad command line usage. * tests/Makefile.am (TESTS): Add bad-usage here.
-rw-r--r--src/patch.c8
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/bad-usage18
3 files changed, 23 insertions, 4 deletions
diff --git a/src/patch.c b/src/patch.c
index 828943b..0255fbb 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -150,6 +150,10 @@ main (int argc, char **argv)
else if ((version_control = getenv ("VERSION_CONTROL")))
version_control_context = "$VERSION_CONTROL";
+ init_backup_hash_table ();
+ init_files_to_delete ();
+ init_files_to_output ();
+
/* parse switches */
Argc = argc;
Argv = argv;
@@ -162,10 +166,6 @@ main (int argc, char **argv)
if (make_backups | backup_if_mismatch)
backup_type = get_version (version_control_context, version_control);
- init_backup_hash_table ();
- init_files_to_delete ();
- init_files_to_output ();
-
init_output (&outstate);
if (outfile)
outstate.ofp = open_outfile (outfile);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 02fc6de..5cea52d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,6 +20,7 @@ TESTS = \
asymmetric-hunks \
backup-prefix-suffix \
bad-filenames \
+ bad-usage \
concat-git-diff \
copy-rename \
corrupt-reject-files \
diff --git a/tests/bad-usage b/tests/bad-usage
new file mode 100644
index 0000000..022eeda
--- /dev/null
+++ b/tests/bad-usage
@@ -0,0 +1,18 @@
+# Copyright (C) 2009, 2011-2012 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# in any medium, are permitted without royalty provided the copyright
+# notice and this notice are preserved.
+
+. $srcdir/test-lib.sh
+
+require_cat
+use_local_patch
+use_tmpdir
+
+# ==============================================================
+
+check 'patch -px || echo "status: $?"' <<EOF
+$PATCH: **** strip count x is not a number
+status: 2
+EOF