patch-2.7.1-initialize-data-structures-early-enough.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From 291ec175812b7ba291d124e4cf2fbf9efec590c8 Mon Sep 17 00:00:00 2001
  2. From: Andreas Gruenbacher <agruen@linbit.com>
  3. Date: Thu, 4 Oct 2012 12:33:09 +0200
  4. Subject: [PATCH] Initialize data structures early enough
  5. * src/patch.c (main): Initialize data structures early enough, before error
  6. paths can access them.
  7. * tests/bad-usage: Test bad command line usage.
  8. * tests/Makefile.am (TESTS): Add bad-usage here.
  9. ---
  10. src/patch.c | 8 ++++----
  11. tests/Makefile.am | 1 +
  12. tests/bad-usage | 18 ++++++++++++++++++
  13. 3 files changed, 23 insertions(+), 4 deletions(-)
  14. create mode 100644 tests/bad-usage
  15. diff --git a/src/patch.c b/src/patch.c
  16. index 828943b..0255fbb 100644
  17. --- a/src/patch.c
  18. +++ b/src/patch.c
  19. @@ -150,6 +150,10 @@ main (int argc, char **argv)
  20. else if ((version_control = getenv ("VERSION_CONTROL")))
  21. version_control_context = "$VERSION_CONTROL";
  22. + init_backup_hash_table ();
  23. + init_files_to_delete ();
  24. + init_files_to_output ();
  25. +
  26. /* parse switches */
  27. Argc = argc;
  28. Argv = argv;
  29. @@ -162,10 +166,6 @@ main (int argc, char **argv)
  30. if (make_backups | backup_if_mismatch)
  31. backup_type = get_version (version_control_context, version_control);
  32. - init_backup_hash_table ();
  33. - init_files_to_delete ();
  34. - init_files_to_output ();
  35. -
  36. init_output (&outstate);
  37. if (outfile)
  38. outstate.ofp = open_outfile (outfile);
  39. diff --git a/tests/Makefile.am b/tests/Makefile.am
  40. index 02fc6de..5cea52d 100644
  41. --- a/tests/Makefile.am
  42. +++ b/tests/Makefile.am
  43. @@ -20,6 +20,7 @@ TESTS = \
  44. asymmetric-hunks \
  45. backup-prefix-suffix \
  46. bad-filenames \
  47. + bad-usage \
  48. concat-git-diff \
  49. copy-rename \
  50. corrupt-reject-files \
  51. diff --git a/tests/bad-usage b/tests/bad-usage
  52. new file mode 100644
  53. index 0000000..022eeda
  54. --- /dev/null
  55. +++ b/tests/bad-usage
  56. @@ -0,0 +1,18 @@
  57. +# Copyright (C) 2009, 2011-2012 Free Software Foundation, Inc.
  58. +#
  59. +# Copying and distribution of this file, with or without modification,
  60. +# in any medium, are permitted without royalty provided the copyright
  61. +# notice and this notice are preserved.
  62. +
  63. +. $srcdir/test-lib.sh
  64. +
  65. +require_cat
  66. +use_local_patch
  67. +use_tmpdir
  68. +
  69. +# ==============================================================
  70. +
  71. +check 'patch -px || echo "status: $?"' <<EOF
  72. +$PATCH: **** strip count x is not a number
  73. +status: 2
  74. +EOF
  75. --
  76. 1.8.0.3