changeset 4623:1da836e15491

6240542 sort order incorrect with multiple fields
author rm88369
date Tue, 10 Jul 2007 01:50:17 -0700
parents 86a7ac7a2ed7
children 06dec993f0b9
files usr/src/cmd/sort/common/fields.c
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/sort/common/fields.c	Mon Jul 09 23:01:19 2007 -0700
+++ b/usr/src/cmd/sort/common/fields.c	Tue Jul 10 01:50:17 2007 -0700
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -481,8 +480,13 @@
 			T++;
 	}
 
-	if ((ret = MAX(T - S, 0) + offset) >= L->l_data_length)
-		return (L->l_data_length);
+	if ((ret = MAX(T - S, 0) + offset) >= L->l_data_length) {
+		if (S[L->l_data_length - 1] == delimiter.sc) {
+			return (L->l_data_length - 1);
+		} else {
+			return (L->l_data_length);
+		}
+	}
 
 	if (is_end && offset == 0)
 		ret--;
@@ -537,8 +541,13 @@
 			T++;
 	}
 
-	if ((ret = MAX(T - S, 0) + offset) >= L->l_data_length)
-		return (L->l_data_length);
+	if ((ret = MAX(T - S, 0) + offset) >= L->l_data_length) {
+		if (S[L->l_data_length - 1] == delimiter.wc) {
+			return (L->l_data_length - 1);
+		} else {
+			return (L->l_data_length);
+		}
+	}
 
 	if (is_end && offset == 0)
 		ret--;
@@ -699,7 +708,7 @@
 	if ((dlength = xfrm_ops->sx_len(compose, clength)) <
 	    L->l_collate_bufsize - coll_offset)
 		return (xfrm_ops->sx_xfrm(L->l_collate.sp + coll_offset,
-			    compose, dlength + 1));
+		    compose, dlength + 1));
 	else
 		return ((ssize_t)-1);
 }
@@ -727,7 +736,7 @@
 	if ((dlength = xfrm_ops->sx_len(compose, clength)) <
 	    L->l_collate_bufsize - coll_offset)
 		return (xfrm_ops->sx_xfrm(L->l_collate.sp + coll_offset,
-			    compose, dlength + 1));
+		    compose, dlength + 1));
 	else
 		return ((ssize_t)-1);
 }