From owner-freebsd-sparc64@freebsd.org Thu Mar 31 11:22:29 2016 Return-Path: Delivered-To: freebsd-sparc64@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 13740AE4F8A for ; Thu, 31 Mar 2016 11:22:29 +0000 (UTC) (envelope-from shige@iee.niit.ac.jp) Received: from nolm01.iee.niit.ac.jp (nolm01.iee.niit.ac.jp [202.243.124.21]) by mx1.freebsd.org (Postfix) with ESMTP id B373717DD for ; Thu, 31 Mar 2016 11:22:28 +0000 (UTC) (envelope-from shige@iee.niit.ac.jp) Received: from pc98tak.iee.niit.ac.jp (pc98tak.iee.niit.ac.jp [202.243.124.33]) by nolm01.iee.niit.ac.jp (8.15.2/8.15.2) with ESMTP id u2VBMPgC000717; Thu, 31 Mar 2016 20:22:26 +0900 (JST) Received: (from shige@localhost) by pc98tak.iee.niit.ac.jp (8.15.2/8.15.2/Submit) id u2VBMPam007017; Thu, 31 Mar 2016 20:22:25 +0900 (JST) (envelope-from shige@iee.niit.ac.jp) Date: Thu, 31 Mar 2016 20:22:25 +0900 (JST) Message-Id: <201603311122.u2VBMPam007017@pc98tak.iee.niit.ac.jp> X-Authentication-Warning: pc98tak.iee.niit.ac.jp: shige set sender to shige@iee.niit.ac.jp using -f From: Shigeharu TAKENO To: freebsd-sparc64@freebsd.org Cc: Joerg Wunsch Subject: Re: /usr/bin/sort may be incorrect In-Reply-To: <20160331072303.GP53011@uriah.heep.sax.de> References: <201603250229.u2P2TVLp003567@pc98tak.iee.niit.ac.jp> <201603310446.u2V4kLGM003303@pc98tak.iee.niit.ac.jp> <20160331072303.GP53011@uriah.heep.sax.de> User-Agent: SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 Emacs/20.7 (i386-unknown-freebsd10.2) MULE/4.0 (HANANOEN) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-BeenThere: freebsd-sparc64@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Porting FreeBSD to the Sparc List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2016 11:22:29 -0000 shige 03/31 2016 ---------------- Thank you for your reply. Joerg Wunsch wrote: | struct key_value | { | struct bwstring *k; | struct key_hint hint[]; | }; | | If that works for you, too, I think it would be the preferrable way to | write it. Unfortunately this does not fix the problem. | > The k field of key_value may be overwritten by the hint field | > in numcoll_impl(), gnumcoll() and monthcoll() (coll.c), and the | > pointer value of k may change to incorrect value. | | Are you saying that something like | | struct key_value *kw; | | ... | | kw->hint[-1] = something; | | happens? That would certainly be a bug in the code then that ought to | be fixed, rather than worked around. I tested under your suggestion "struct key_hint hint[]", which behaves as the same of default sort command. % ( echo 2 5 8 ; echo 2 6 5 ) | sort -n +0 -1 +1 -2 +2 -3 In key_coll(struct keys_array *ps1, struct keys_array *ps2, size_t offset) (in coll.c), initial pointer values are the followings: &(ps1->key[0]) = 0x40c140f8 &(ps1->key[1]) = 0x40c14100 &(ps1->key[2]) = 0x40c14108 &(ps2->key[0]) = 0x40c14088 &(ps2->key[1]) = 0x40c14090 &(ps2->key[2]) = 0x40c14198 (the pointer repeat is only 8 byte.) ps1->key[0].k = 0x40c060e0 ps1->key[1].k = 0x40c060f0 ps1->key[2].k = 0x40c06100 ps2->key[0].k = 0x40c060a0 ps2->key[1].k = 0x40c060b0 ps2->key[2].k = 0x40c060c0 key_coll() calls sm->func() = numcoll(), and it uses numcoll_impl(struct key_value *kv1, struct key_value *kv2) with ps1->key[i] and ps2->key[i]. The function numcoll_impl() uses k field and hint field of struct key_value. For i = 0, the k field pointers of arguments kv1 and kv2 of numcoll_impl() are correct: kv1->k = 0x40c060e0, kv2->k = 0x40c060a0 but the hint field pointers of kv1, kv2 are doughtful: &(kv1->hint) = 0x40c14100, &(kv2->hint) = 0x40c14090 which are the same value of &(ps1->key[1]) and &(ps2->key[1]). And for i = 1, the k field pointers of arguments kv1 and kv2 become incorrect: kv1->k = 0x140c060f0, kv2->k = 0x140c060b0 which are added 0x100000000 to the original pointer value. The sort command stops where it uses the value. If we use the definition "struct key_hint hint[1]", the repeat of pointers of ps1->key[i] becomes 32 byte, and incorrect changes of pointers do not occur. &(ps1->key[0]) = 0x40c08208 &(ps1->key[1]) = 0x40c08228 &(ps1->key[2]) = 0x40c08248 +========================================================+ Shigeharu TAKENO NIigata Institute of Technology kashiwazaki,Niigata 945-1195 JAPAN shige@iee.niit.ac.jp TEL(&FAX): +81-257-22-8161 +========================================================+