From patchwork Mon Jul 17 14:29:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9845307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 61D236037F for ; Mon, 17 Jul 2017 14:31:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55DC5284B5 for ; Mon, 17 Jul 2017 14:31:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A9D62856A; Mon, 17 Jul 2017 14:31:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC30A284B5 for ; Mon, 17 Jul 2017 14:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751372AbdGQOaj (ORCPT ); Mon, 17 Jul 2017 10:30:39 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:55229 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751278AbdGQOai (ORCPT ); Mon, 17 Jul 2017 10:30:38 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0LfFcq-1dzcJX1QQC-00ojqZ; Mon, 17 Jul 2017 16:30:27 +0200 From: Arnd Bergmann To: Hans Verkuil , Mauro Carvalho Chehab Cc: Arnd Bergmann , Sakari Ailus , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] [media] usbvision-i2c: fix format overflow warning Date: Mon, 17 Jul 2017 16:29:58 +0200 Message-Id: <20170717143024.862161-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:5WKkg8wP20R/GTtomQDY+b7rb4DRcQLwvLb5A6s3n2lQbmULLDy pXAfLlGI27QpJ22t+atI71sUHIX0hXF4MA3PJPPTj8RNEZIOkGy6bsksac1pfRbPAogUGDG sg8BeS9ufzGniI7qFDDhSiteBDVm23VQYrzmvfFRVtYcFnuYxgEU+b5AZ7wYyAYBIj1/WEM tOXDtlBl5uzJtFKfDOFNA== X-UI-Out-Filterresults: notjunk:1; V01:K0:UH9kr4Idt2A=:tevAaSviuHlP0KHw60btEJ r09iaqGD1amu1cwjJKdrN66HmzbbEyTOhkfSncchlIN6XVYx8p6GwW2bmPFTXcB+pHpr6kRuf WSf3WVbZ9fPyanlaUyxpULsIhH7ikU8lSJtyCZDaI8pDCx4/q+D9Q+W0qVdDFZrYWBIk5U4AJ g1oRAW0CCVcdLqKGBRE2R91CagvMSzVkZZ3V2EjXsVqZdnCGhGk+9U8JXjkshii49ZgC/ykjb vtxwoKJCNWKu3eke1f3gbdq/pMAZh8OR4d3jJ3kfLpYkB+AmOhxoESF+uIeAKXKeDFXarMl1n Wr75cjiHXZAbQWKKX8lYl1KnKVZPGK93Pys9oMSOAh3dsXhiry1/dIWA0/8gzdoBjYC/qlDqK RuYU75uue30n4/qLIANKK7HNcnCCUGJuXHqOWbgBeY9a7aSFJnBuHvPl87SDdHihjF8eFdjvw qqjrzY0qMIO6C1R+p1DrUTE8JjGUITKavVK2+wvIdUuiqW9yJ/Bzyj7f4HrNhIETg2MZhT0fk soEcNEV10hZ/DOVG6OIrwPdBjLfkvuWNTelLtZ458UiGIkPme3H5flGtiNAN24oejDYm9Fv9b JUpcbB21v9OUW6naBmw/SR+aB+xK1JtKgmJ/N6htRJGgPRzMendhjwJ7CTQHVE9df3rpacw7V y8gG42NJGitgA1q7SyYKooX6iLmPfZZQCRMXSYrXWsaTY7SmeI3e9a/uOrppb3722vLlBePuf 9zqqLVYj5kJmkAuiOj5XiKYX/XpqYFPKZTFbOA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP gcc-7 notices that we copy a fixed length string into another string of the same size, with additional characters: drivers/media/usb/usbvision/usbvision-i2c.c: In function 'usbvision_i2c_register': drivers/media/usb/usbvision/usbvision-i2c.c:190:36: error: '%d' directive writing between 1 and 11 bytes into a region of size between 0 and 47 [-Werror=format-overflow=] sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name, ^~~~~~~~~~ drivers/media/usb/usbvision/usbvision-i2c.c:190:2: note: 'sprintf' output between 4 and 76 bytes into a destination of size 48 Using snprintf() makes the code more robust in general, but will still trigger a possible warning about truncation in the string. We know this won't happen as the template name is always "usbvision", so we can easily avoid the warning as well by using this as the format string directly. Signed-off-by: Arnd Bergmann --- v2: use snprintf() --- drivers/media/usb/usbvision/usbvision-i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/usbvision/usbvision-i2c.c b/drivers/media/usb/usbvision/usbvision-i2c.c index fdf6b6e285da..38749331e7df 100644 --- a/drivers/media/usb/usbvision/usbvision-i2c.c +++ b/drivers/media/usb/usbvision/usbvision-i2c.c @@ -187,8 +187,9 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision) usbvision->i2c_adap = i2c_adap_template; - sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name, - usbvision->dev->bus->busnum, usbvision->dev->devpath); + snprintf(usbvision->i2c_adap.name, sizeof(usbvision->i2c_adap.name), + "usbvision-%d-%s", + usbvision->dev->bus->busnum, usbvision->dev->devpath); PDEBUG(DBG_I2C, "Adaptername: %s", usbvision->i2c_adap.name); usbvision->i2c_adap.dev.parent = &usbvision->dev->dev;