From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.perfora.net (mout.perfora.net [74.208.4.197]) by server2.sourceware.org (Postfix) with ESMTPS id A4857387102A for ; Sat, 7 Mar 2020 11:39:37 +0000 (GMT) Received: from MBP-2016.fios-router.home ([74.104.151.201]) by mrelay.perfora.net (mreueus004 [74.208.5.2]) with ESMTPA (Nemesis) id 1MDyDQ-1j2sHz2Gay-009ypR for ; Sat, 07 Mar 2020 12:39:35 +0100 Subject: Re: There is a bug on sprintf newlib when using specifier %-*.llu To: newlib@sourceware.org References: From: Richard Damon Message-ID: <25f7a431-4894-b8df-3e62-f8baa7b9f59d@Damon-Family.org> Date: Sat, 7 Mar 2020 06:39:33 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Provags-ID: V03:K1:E9/2LjfNAHQxQDprwNx6jX5B1zIT4m710BOokUcelwS3kXEX9TA Q+IQjmRMjTOyHcbKAwul/Yz/mr5bjV51MyjlFnyLKnVQOhPTj63sJbmSu7oU2nGeE0Vj4dZ HVfaEDcHUO9q5SmsdAkcSgksvjvmdkrnjh3qGUmG9Y5qMZXq5kkXtJuMEa5Vh5CMDkUaVmN rAVm9pkkwOCK9KEmv2zCw== X-UI-Out-Filterresults: notjunk:1;V03:K0:THdCvhJW/HI=:RrtdJbvwRSm6lxbHBd0pH8 UpT02+3EMzK4qIQ56VeldoVZgfwZ7BS4xb2s2qbmBBqslDPFpc20nQZKy1x8YHtUcUc0/YFKF 0m5/FistCIwpeYJKEbUgXh2QxLQxCfcbjzVgMGiF3pfQiihyezYHmdIlwgPNH0gZJP6IzRt36 iashtMG3gQOY/xa2evuRDm7SlWvG7lu4bkDX8ZInFgkKBg5uZNTd+WoCPwlMSQ1N6QdFegVTh kfe3rQ1/Oud5vO9WB1PoGnqvEvUMJYxLvpO4krF6s1bQ/4jioYN7MZSoBdUob7agobep/0UbN fm1fi/hf25cr7aDEHnd9eD7znE3OrbvIsjBB6OCdfitbyhPhatsM83q17ZovyIpRT8WDPRD2R BQmL417mLcEmicMQbLLzQSkTTG+BGOSJVYuuQy501l9mtbv5d9z48sD1M3IkeIItNRNmXTpyX 9UQjOj7J4JwxR+EdIVjpE6T6sGq7/U5BRYDNRmmHHIxcm6LvpxijszjQGFzM4lrdtmQDpqau3 xBiU9M9PHm/dfFtWRlIQsi8bcXVWpv6etB5lATVRAgfED3JOB3RiKNQB1okPvetX90gJvrREM zMir1zwoQZTn+klot9gpqj4aFVHK2LN1Y3WdK4dZFzHjU375YAKYB1lCzm2XXCsOoV2vIe9ej LxNAslUVI4eMAUnA6wpqvqDkXHh3r3zBnMd2XNPMxAI2aizWfB1gD1CF361eq35Sh5E8pn7Jk OyRpkF8t7I+cFm9aWxALZxCDl6FUGySAG9ydF30cngnrPFo2wGy5DL3nN9B/c8T+zmMn7Y4GC 6Du/3SfGW8IiE+yNftogFQdAMQy0IfI1F1ise/IgXToiN1Tb1AQAY7tMBsSg/aE1vAwjrsx X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Mar 2020 11:39:38 -0000 On 3/7/20 3:30 AM, ng boon khai wrote: > Hi, > > I found a bug when using the newlib sprinf using the spcifier %-*.llu > > Below is the code snippet > > function (){ > int64_t longval; > longval=(int64_t)(1); > char comparebuf[2000]; > sprintf(comparebuf, "testing string! arg1=%-*.llu, arg2=%-*.llu",1,longval,1,longval); > printf(comparebuf); > } > > And i get this outcome > testing string! arg1=499644, arg2= > > Expected outcome should be > testing string! arg1=1, arg2=1 > > Regards, > Ng Boon Khai. > One issue with your program is that you have a variable of type int64_t but using a format that expects an unsigned long long. In some implementations, long long might be 64 bits, but in others long long will be 128 bits. If you want to print an int64_t, you should be using the format specified from the macro PRId64 If you want to use llu, you should be using a variable of type unsigned long long -- Richard Damon