--- a/toys/posix/sort.c	2014-10-02 18:23:27.000000000 +0530
+++ b/toys/posix/sort.c	2014-10-16 03:52:00.726879945 +0530
@@ -81,7 +81,7 @@
 struct sort_key
 {
   struct sort_key *next_key;  // linked list
-  unsigned range[4];          // start word, start char, end word, end char
+  int range[4];          // start word, start char, end word, end char
   int flags;
 };
 
@@ -94,7 +94,7 @@
   // Special case whole string, so we don't have to make a copy
 
   if(key->range[0]==1 && !key->range[1] && !key->range[2] && !key->range[3]
-    && !(flags&(FLAG_b&FLAG_d&FLAG_f&FLAG_i&FLAG_bb))) return str;
+    && !(flags&(FLAG_b|FLAG_d|FLAG_f|FLAG_i|FLAG_bb))) return str;
 
   // Find start of key on first pass, end on second pass
 
@@ -112,10 +112,10 @@
           while (isspace(str[end])) end++;
 
         // Skip body of key
-        for (; str[end]; end++) {
+        for (; str[end];) {
           if (TT.key_separator) {
-            if (str[end]==*TT.key_separator) break;
-          } else if (isspace(str[end])) break;
+            if (str[end++]==*TT.key_separator) break;
+          } else if (isspace(str[end++])) break;
         }
       }
     }
@@ -319,9 +319,11 @@
       temp = arg->arg;
       while (*temp) {
         // Start of range
-        key->range[2*idx] = (unsigned)strtol(temp, &temp, 10);
+        if ((key->range[2*idx] = strtol(temp, &temp, 10)) < 0) 
+          error_exit("bad field value");
         if (*temp=='.')
-          key->range[(2*idx)+1] = (unsigned)strtol(temp+1, &temp, 10);
+          if ((key->range[(2*idx)+1] = strtol(temp+1, &temp, 10)) < 0)
+            error_exit("bad field value");
 
         // Handle flags appended to a key type.
         for (;*temp;temp++) {
@@ -355,6 +357,9 @@
     }
   }
 
+  if ((toys.optflags & FLAG_t) && (!TT.key_separator[0] 
+        || TT.key_separator[1]))
+    error_exit("multi char -t arg");
   // global b flag strips both leading and trailing spaces
   if (toys.optflags&FLAG_b) toys.optflags |= FLAG_bb;
 
@@ -374,7 +379,8 @@
   // handle unique (-u)
   if (toys.optflags&FLAG_u) {
     int jdx;
-
+    
+    toys.optflags |= FLAG_s;
     for (jdx=0, idx=1; idx<TT.linecount; idx++) {
       if (!compare_keys(&TT.lines[jdx], &TT.lines[idx]))
         free(TT.lines[idx]);
