[hackers] [sbase] tr: set2 must be set in some cases || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sat, 10 Jan 2015 19:16:47 +0100 (CET)

commit 14c5ab48d504c35fd0f4d196ca11e6f9a6aaff33
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat Jan 10 19:08:54 2015 +0100

    tr: set2 must be set in some cases
    
    echo abc | tr 'a' '' would crash because of:
    
            m--;
            r = set2[m].start + (off1 - off2) / set2[m].quant;
    
    if set2ranges > 0 it's fine.

diff --git a/tr.c b/tr.c
index 03a7c2a..973c73b 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -196,6 +196,8 @@ main(int argc, char *argv[])
         set1ranges = makeset(argv[0], &set1);
         if (argc == 2)
                 set2ranges = makeset(argv[1], &set2);
+ if (!dflag && !set2ranges)
+ eprintf("set2 must be non-empty\n");
 read:
         if (!readrune("<stdin>", stdin, &r))
                 return 0;
Received on Sat Jan 10 2015 - 19:16:47 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 10 2015 - 19:24:09 CET