From patchwork Sun Nov 4 14:21:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1694331 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 17F1D3FD2B for ; Sun, 4 Nov 2012 14:21:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754293Ab2KDOV2 (ORCPT ); Sun, 4 Nov 2012 09:21:28 -0500 Received: from mail-gh0-f174.google.com ([209.85.160.174]:45897 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753779Ab2KDOV2 (ORCPT ); Sun, 4 Nov 2012 09:21:28 -0500 Received: by mail-gh0-f174.google.com with SMTP id g15so874788ghb.19 for ; Sun, 04 Nov 2012 06:21:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=6+CWk4h8xJf+3DcnrO/yFI9wUfD7reQDAFSCV0VPgCI=; b=YfG1oFTKjHpPT/KpvWdKkvDGgkd94GBKVT2KuLt6us1v3cVZNOoxhoDkGDG2qYrpAo of2svCF+ESkMu3lcS5mOZvbfpK5q3P72QXPPYSZV0/0+cJydfrlGklJwc28duK6pPkSP SU4tZ5xulCQ9raxhYJjsR13cCjIsnr1chwsR8TuaJYas+2ZUpSC0MvRvT85weguRCMm1 R8BB55p33+UalR8aJeZCTsSKUDVQtFL/KcfMkvmE3HDUsAwJmqxaGjIav0cI42xwWDwa 60kUKaTkYEEd+8lgCEZQxpNIQGZWAwS1QgPbluqM7F/pe+S7gUFgBjCoe6mfDU9v32yX dmFw== Received: by 10.236.48.37 with SMTP id u25mr6728418yhb.4.1352038887571; Sun, 04 Nov 2012 06:21:27 -0800 (PST) Received: from salusa.poochiereds.net (cpe-107-015-110-129.nc.res.rr.com. [107.15.110.129]) by mx.google.com with ESMTPS id e24sm14987716yhh.4.2012.11.04.06.21.25 (version=SSLv3 cipher=OTHER); Sun, 04 Nov 2012 06:21:26 -0800 (PST) From: Jeff Layton To: linux-cifs@vger.kernel.org Cc: shirishpargaonkar@gmail.com Subject: [PATCHv2 12/17] setcifsacl: clean up parse_cmdline_aces Date: Sun, 4 Nov 2012 09:21:22 -0500 Message-Id: <1352038882-9100-1-git-send-email-jlayton@samba.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1351947034-18876-13-git-send-email-jlayton@samba.org> References: <1351947034-18876-13-git-send-email-jlayton@samba.org> X-Gm-Message-State: ALoCoQlI948kLYhS5lfYtHyztaaWycF2JxQZ3ZUOzkcLBmQfUDDPMYSdZ1tAFnjKxBC8srtqfm/V Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org One of the reasons to use "goto" in an error condition is to eliminate unnecessary indentation. Fix that here by revering some error checks end getting rid of some unneeded "else" cases. After using strstr() to find "ACL:", there's no need to then use strchr() to find ':'. We know where it is -- it's 3 bytes past the current position. Finally, there's no need to copy these strings into new buffers, just set the pointers in the array to their original values. Signed-off-by: Jeff Layton --- setcifsacl.c | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/setcifsacl.c b/setcifsacl.c index 9d194cd..02c8a35 100644 --- a/setcifsacl.c +++ b/setcifsacl.c @@ -655,48 +655,36 @@ build_cmdline_aces_ret: } static char ** -parse_cmdline_aces(char *optarg, int numcaces) +parse_cmdline_aces(char *acelist, int numcaces) { int i = 0, len; char *acestr, *vacestr, **arrptr = NULL; - errno = EINVAL; arrptr = (char **)malloc(numcaces * sizeof(char *)); if (!arrptr) { - printf("%s: Error %d allocating char array\n", __func__, errno); + printf("%s: Unable to allocate char array\n", __func__); return NULL; } while (i < numcaces) { - acestr = strtok(optarg, ","); /* everything before , */ - if (acestr) { - vacestr = strstr(acestr, "ACL:"); /* ace as ACL:*" */ - if (vacestr) { - vacestr = strchr(vacestr, ':'); - if (vacestr) - ++vacestr; /* go past : */ - if (vacestr) { - len = strlen(vacestr); - arrptr[i] = malloc(len + 1); - if (!arrptr[i]) - goto parse_cmdline_aces_ret; - strcpy(arrptr[i], vacestr); - ++i; - } else - goto parse_cmdline_aces_ret; - } else - goto parse_cmdline_aces_ret; - } else - goto parse_cmdline_aces_ret; - optarg = NULL; - } - errno = 0; + acestr = strtok(acelist, ","); /* everything before , */ + if (!acestr) + goto parse_cmdline_aces_err; + + vacestr = strstr(acestr, "ACL:"); /* ace as ACL:*" */ + if (!vacestr) + goto parse_cmdline_aces_err; + vacestr += 4; /* skip past "ACL:" */ + if (*vacestr) { + arrptr[i] = vacestr; + ++i; + } + acelist = NULL; + } return arrptr; -parse_cmdline_aces_ret: - printf("%s: Error %d parsing ACEs\n", __func__, errno); - for (; i >= 0; --i) - free(arrptr[i]); +parse_cmdline_aces_err: + printf("%s: Error parsing ACEs\n", __func__); free(arrptr); return NULL; } @@ -908,8 +896,6 @@ setcifsacl_cmdlineverify_ret: free(cacesptr); setcifsacl_cmdlineparse_ret: - for (i = 0; i < numcaces; ++i) - free(arrptr[i]); free(arrptr); setcifsacl_numcaces_ret: