From patchwork Sun Jul 23 19:23:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 792581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-458730-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ld07xevk"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xFvZ85bpcz9s65 for ; Mon, 24 Jul 2017 05:23:58 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=mwgrKGoMfoIDCJ4vHKwq/0qi+141H/FcN9zy6Inw4WZZknBzJb J2Q4bXU62qJpIjkSGAcGx7fwBuJNntNt36eetZpGJ1qtrubMfR+h+gbLVFSyA7eZ vFtjaGcLryvmGmof7a/gVn62qv4cFKYqDj4cL8qwlW28sqBYES1sPJ8OQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=CRlZh4ve4PLoDYmbXMsQYt+aoGI=; b=ld07xevkO18pBPzMs1RT +ErBnsOzgEHA7pSUVLNTw+bYE4HWA47YEoEU3ejsegp/y7kUiU7yO5NlCAIFP2So 6P2MJ7ljD5iqIoGexgr7O0Vjx/3WKYBVnG0cOXjjBLvzwEQpT1MQtE41sl3ay99k hEib6E3oQkyWYtJSSaXHIAE= Received: (qmail 11146 invoked by alias); 23 Jul 2017 19:23:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9247 invoked by uid 89); 23 Jul 2017 19:23:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout2.netcologne.de Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 23 Jul 2017 19:23:41 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id D4AE3125AF; Sun, 23 Jul 2017 21:23:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id CFFB211D8D; Sun, 23 Jul 2017 21:23:37 +0200 (CEST) Received: from [78.35.128.55] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 5974f7b9-022c-7f0000012729-7f0000019bf3-1 for ; Sun, 23 Jul 2017 21:23:37 +0200 Received: from [192.168.178.20] (xdsl-78-35-128-55.netcologne.de [78.35.128.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Sun, 23 Jul 2017 21:23:36 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, libfortran] Fix PR 80365, undefined memcpy Message-ID: Date: Sun, 23 Jul 2017 21:23:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Hello world, the attached test cases fixes a problematic invocation of memcpy where src=NULL and n=0 by simply doing nothing in the surrounding function if there is nothing to be done. No test case, because this only shows up with a sanitized libgfortran or under a debugger. OK for trunk? Regards Thomas 2017-07-23 Thomas Koenig * io/unix.c (buf_write): Return early if there is nothing to write. Index: io/unix.c =================================================================== --- io/unix.c (Revision 249936) +++ io/unix.c (Arbeitskopie) @@ -582,6 +582,9 @@ static ssize_t buf_write (unix_stream *s, const void *buf, ssize_t nbyte) { + if (nbyte == 0) + return 0; + if (s->ndirty == 0) s->buffer_offset = s->logical_offset;