aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorStefan Eßer <se@FreeBSD.org>2013-05-23 20:57:20 +0000
committerStefan Eßer <se@FreeBSD.org>2013-05-23 20:57:20 +0000
commit6b239879f8618cbe72ce0487d65eb231c35c2fd1 (patch)
tree712b2d1d3d7fe2956f3c85a07bce8dec224e5986 /usr.bin
parent08ad1a7ac6406722ab06c14e81ae4317a6e3c35f (diff)
downloadsrc-6b239879f8618cbe72ce0487d65eb231c35c2fd1.tar.gz
src-6b239879f8618cbe72ce0487d65eb231c35c2fd1.zip
Fix target selection logic, which did not comply with the man page.
Instead of using the file with the least order of path name components, shortest filename and finally the shortest basename (with the search stopping as soon as one of these conditions is true), the first filename checked was used as the reference, and another filename was only selected if all of the above comparisons are in favour of the latter file. This was wrong, because filenames with path less components were only considered, if both of the other conditions were true as well. In fact, the first filename to be checked had good chances to be selected in the end, since it only needed to be better with regard to any one of the three criteria ... Reviewed by: delphij@freebsd.org
Notes
Notes: svn path=/head/; revision=250943
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/patch/pch.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index 4c06bbffd442..411dcac0c931 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -1537,10 +1537,16 @@ best_name(const struct file_name *names, bool assume_exists)
continue;
if ((tmp = num_components(names[i].path)) > min_components)
continue;
- min_components = tmp;
+ if (tmp < min_components) {
+ min_components = tmp;
+ best = names[i].path;
+ }
if ((tmp = strlen(basename(names[i].path))) > min_baselen)
continue;
- min_baselen = tmp;
+ if (tmp < min_baselen) {
+ min_baselen = tmp;
+ best = names[i].path;
+ }
if ((tmp = strlen(names[i].path)) > min_len)
continue;
min_len = tmp;