From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id EFF4C1F5A2 for ; Sun, 9 Feb 2020 14:45:09 +0000 (UTC) Received: from localhost ([::1]:51780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j0npc-0007QH-1s for normalperson@yhbt.net; Sun, 09 Feb 2020 09:45:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42089) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j0npG-0007PN-9T for bug-gnulib@gnu.org; Sun, 09 Feb 2020 09:44:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j0npC-0006zN-3e for bug-gnulib@gnu.org; Sun, 09 Feb 2020 09:44:46 -0500 Received: from 83-233-229-139.cust.bredband2.com ([83.233.229.139]:50845 helo=mail.gisladisker.se) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j0npB-0006wc-TB for bug-gnulib@gnu.org; Sun, 09 Feb 2020 09:44:42 -0500 Received: by mail.gisladisker.se (Postfix, from userid 1002) id B9CFE4E848; Sun, 9 Feb 2020 15:44:34 +0100 (CET) Date: Sun, 9 Feb 2020 15:44:34 +0100 From: Mats Erik Andersson To: bug-gnulib@gnu.org Subject: Possible testing case of snprintf. Message-ID: <20200209144434.GA19087@aun.utmark.mea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Message-Flag: Do not send HTML. HTML undanbedes. User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 83.233.229.139 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hello there! This note has its origin in a report received at bug-inetutils. The following test code for snprintf() is a simplyfied detection I have implemented as a warning-only test in Gnu Inetutils. My point is that Linux/glibc and kfreebsd/glibc triggers this warning, but OpenSolaris, OpenIndiana, FreeBSD, OpenBSD, NetBSD, and DragonflyBSD do not! Reading the replacement code for the Gnulib module snprintf, neither would your function, should it undergo the test. In conclusion, this is a case where the native glibc function snprintf() behaves worse than does your replacement. #define MESSAGE "try a fool" #define WRONG_MESSAGE "fool" char msg[sizeof (MESSAGE)] = "try a "; snprintf (msg, sizeof (msg), "%s%s", msg, WRONG_MESSAGE); if (!strcmp (msg, WRONG_MESSAGE)) printf ("Warning! snprintf got confused!\n"); Observe that `msg' is target, as well as source. POSIX mentions nothing about such a use case, but glibc will produce "fool", whereas all BSD unices as well as OpenSolaris descendants will produce "try a fool". Tacitly, POSIX would probably cry out a statement like "Undefined"! It is my opinion that this discrepancies should at least be documented in 'snprintf.texi', were you not to take matter so far as to include this as some sort of test, after due elaboration. Gnu Inetutils uses legacy code from BSD4.4, where the related use is present and did not cause troubles, but as the recent report submitted to us, the code does produce portability issues when brought to glibc. It has taken a long time to discover this state of affaires, but now it has surfaced! On behalf of Gnu Inetutils, Mats Erik Andersson.