From patchwork Fri Jul 18 12:53:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 4583171 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6E1E49F26C for ; Fri, 18 Jul 2014 12:56:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A658220176 for ; Fri, 18 Jul 2014 12:56:11 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.kernel.org (Postfix) with ESMTP id 20F2C2011E for ; Fri, 18 Jul 2014 12:56:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s6ICrKbw000447; Fri, 18 Jul 2014 08:53:21 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s6ICrJxP029679 for ; Fri, 18 Jul 2014 08:53:19 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6ICrJiD019017 for ; Fri, 18 Jul 2014 08:53:19 -0400 Received: from sf1.bxl.stone.is (sf1.bxl.stone.is [87.238.167.36]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6ICrFrE004347 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 18 Jul 2014 08:53:17 -0400 Received: from [87.238.167.34] (helo=smtprelay.1eurohost.com) by sf1.bxl.stone.is with esmtp (Exim 4.82) (envelope-from ) id 1X87f2-00066w-6Z; Fri, 18 Jul 2014 14:53:18 +0200 Received: from vz19.stone-is.net (vz19.stone-is.net [87.238.162.57]) by smtprelay.1eurohost.com (Postfix) with ESMTP id A4A0722088A; Fri, 18 Jul 2014 14:53:11 +0200 (CEST) X-No-Relay: not in my network X-No-Relay: not in my network X-No-Relay: not in my network X-No-Relay: not in my network Received: from [192.168.1.117] (178-119-65-67.access.telenet.be [178.119.65.67]) by vz19.stone-is.net (Postfix) with ESMTPSA id 19E7389386; Fri, 18 Jul 2014 14:53:13 +0200 (CEST) Message-ID: <53C918B7.3010704@acm.org> Date: Fri, 18 Jul 2014 14:53:11 +0200 From: Bart Van Assche User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: christophe.varoqui@opensvc.com References: <53C91871.9070402@acm.org> In-Reply-To: <53C91871.9070402@acm.org> X-Enigmail-Version: 1.6 X-Filter-ID: XtLePq6GTMn8G68F0EmQvdthj6rk7ohlAkaRQG+cDaLZlN3ufQ0ZRHdy43341LQ0JYRGiu4wDuX/ sGw1Y7RAsQVCOi2K3ZygpdQwUC1xM8uHTLHcW1YhPsFnFxvjWlQPLZy1RAw8+2yZuh2VuYuU9z8U a6+MdljsDo+RKX0yPPDwoVJnpeAWJjfTvWCbG36LwJOqJV51iSPXek1m27w/m+HNZvRbeH/WodDC Pyd1hEHbiTiodCOnGJJ238+JDuVLvDps7Pj5KVnOWlZTiUYoWn9T+OwfgRcaB9RPsshfI97D4gz4 tcU5YI1KNYsC2/V3glLeZCD1voA8s0bkUEtPw/GX+ObfaU6whL8xq/xH+as21Cee63EeltfbuaMM NA5XR/lhzJ4Pd6XOYPUh1LatWl4K/BrAvODv+H53lohFBx5WhVa6zifUH6X26a/6lVhrtJVcNrFf 4GaM5Eg5slNOY1NHQAvSZpDy3ysxabiXOiY8rN5kPduYoOjRk/4SxcBWjjQNtXRKSR1sOD289304 szpgkzbBMkWtGTUmSRdnNNTqrNZ1EgtZond7q2FKC0V2+YWH17XvRdXB+H9Qolenz708KlEIRB/1 zhErtZP4jFj74O4hBSz/kkmPgL+fgIguDhk6bX9+PahjGibRg2huPa+y3C4hZbW1xqfNd0+TxuZC YQFAaVzdCWGrYSxZLSwRVJTgfQ351CyXUcSXRzGdsQ== X-Report-Abuse-To: spam@sf1.bxl.stone.is X-Filter-Fingerprint: cPaH8lomer6UwsJ3BnJDyh/24V0ZnPLChpTdx0aQyMi0VFDyP20las9Mq1v6nXmfrqKtWpHLpkE8 c09GKJn2t5ozOYPgkc1huhjdC90TuD9MqRJTan78INzQLlEGX/jFRST5X0bRoOLYozD+qqgg13U4 H51jyCSmLdA2hPaiVpwYWaeThsiFlmPt/lOSmjPeFMozYrgfrkHS49y862jNMmqK95LAXg+Ea3Jb F9WwpaZ//Un1C5ivAWoOksRE8XtOTT9J6CK2j8j7/AJ9TNml+IbyXSJXjZjMx+Tok7jY2RMyI03C PxOnHNHk/4lRyw1K2+vbOPaWIYYs/b+BGdQPit3bIlgnMyP/cGqvZkyMAF3M4vJSyF32VcY65kkk G7YHBc0PjA1KybkFuAXs6dU3HYbGRTQyUTxREijknZAoyXHLKGJAIxMs8rFPbzxQvmW2t0FnLazF NlMYtQg13AFFtw== X-Originating-IP: 87.238.167.34 X-SpamExperts-Domain: stone.is X-SpamExperts-Username: 87.238.167.34 Authentication-Results: bxl.stone.is; auth=pass smtp.auth=87.238.167.34 X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.08) X-Recommended-Action: accept X-RedHat-Spam-Score: -1.235 (BAYES_00,SPF_SOFTFAIL) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.21 X-loop: dm-devel@redhat.com Cc: device-mapper development , Sebastian Herbszt Subject: [dm-devel] [PATCH 2/5] libmultipath: Simplify read_line() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Let read_line() zero-terminate the buffer it returns such that its callers do not have to clear that buffer before calling read_line(). Signed-off-by: Bart Van Assche --- libmultipath/parser.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index 0d4c870..b7bdfcc 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -282,18 +282,12 @@ out: int read_line(char *buf, int size) { - int ch; - int count = 0; - - while ((ch = fgetc(stream)) != EOF && (int) ch != '\n' - && (int) ch != '\r') { - if (count < size) - buf[count] = (int) ch; - else - break; - count++; - } - return (ch == EOF) ? 0 : 1; + char *p; + + if (fgets(buf, size, stream) == NULL) + return 0; + strtok_r(buf, "\n\r", &p); + return 1; } vector @@ -341,7 +335,6 @@ read_value_block(void) } free_strvec(vec); } - memset(buf, 0, MAXBUF); } FREE(buf); return elements; @@ -379,7 +372,6 @@ alloc_value_block(vector strvec, void (*alloc_func) (vector)) free_strvec(vec); } - memset(buf, 0, MAXBUF); } FREE(buf); return 0; @@ -489,8 +481,6 @@ process_stream(vector keywords) while (read_line(buf, MAXBUF)) { line_nr++; strvec = alloc_strvec(buf); - memset(buf,0, MAXBUF); - if (!strvec) continue;