From patchwork Mon Sep 16 11:25:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15096 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 16FE6448FB1 for ; Mon, 16 Sep 2019 14:25:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ED857688129; Mon, 16 Sep 2019 14:25:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F3562687F4A for ; Mon, 16 Sep 2019 14:25:27 +0300 (EEST) Received: by mail-pg1-f174.google.com with SMTP id u72so19647574pgb.10 for ; Mon, 16 Sep 2019 04:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X2QZV4Rzck4e68fBVTfATwQJbCrg2AMTaQraYv88Xck=; b=UDq+KcjD0o+ZPPNFUHfB78Q7KEzkitkuPO6Tq4p5/BSVehK65YXDYdd2nb6zYyY6GC Krh4ozhzjdI4KUwfHAvc8kP6G+XfhVcsexIGZbyhqrDcH7mbTR4P1/pKIufMrkFOi2gi 2O8Bi9dfskXE9J3LHekmxqR3umHv2rAc1+RZ7FBenNvDbO5b7HO/yQ0fvjPDjprWc8nh Ued2tY0nQ4MOJS2KtsdTNJPPW633gFoebzVBR2kbLb/WXoMO7WZFjbNgnKuSFQFe5OxS sEI68s+B1sX3CWgDEsYzKtIV1VIffAlFQgMganYYnrrnZ8IKIe4JPH0sMKK2IQoXiTA2 cxLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X2QZV4Rzck4e68fBVTfATwQJbCrg2AMTaQraYv88Xck=; b=MGyf0KNgbo1O9ed1h3wAJ08goKiqyLyCE+kIhF53H0kqqgYhy+WvL7lf22VfUCFmYH dvJv70pOzHKylmP/hxWRmNxqiRzbpQSEmFKQEyhK+TryE1cB1Cd0T7fnCNIeATJkeMn/ fLz4eGlgX5Od4drju70EUOF1K+h6YejQ2kSQraqLpR6fp3c8+VaY5m5VgobcLc9Vs+do 0NCQJxE3HA89BRB/6i7jgWjVAFea8L8K4lNEAxkaF54566gIR6CDYlLnRLxvoiKpsPgf hU+j+Qv+a4Sq8GKRmgCOqlpIL7NIGRbUQSvElkoiJPohMe5QVm534+9zW5uASaZIdoyk 6cIA== X-Gm-Message-State: APjAAAVoiT2H7jti4PAtL74InFupetiKJRFltEQ9l6BsrfOXZFzHPJPa ThuWvEXqifVj6HooR5JTmjhXq8+E X-Google-Smtp-Source: APXvYqx3W27l1AQB2OAUAntgtd9eDf6xSxvOi4bkp6Pt9FETZg8XQKEBdbCn39P8U7slgT4lFFX8cA== X-Received: by 2002:a63:5926:: with SMTP id n38mr24257025pgb.258.1568633126088; Mon, 16 Sep 2019 04:25:26 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id d14sm9985039pjx.8.2019.09.16.04.25.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Sep 2019 04:25:25 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 16 Sep 2019 19:25:13 +0800 Message-Id: <20190916112516.14285-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <1568595818-7943-1-git-send-email-lance.lmwang@gmail.com> References: <1568595818-7943-1-git-send-email-lance.lmwang@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/4] avutil/avstring: support input path is a null pointer or empty string X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Reviewed-by: Tomas Härdin Reviewed-by: Liu Steven Signed-off-by: Limin Wang --- libavutil/avstring.c | 12 ++++++++---- libavutil/avstring.h | 13 +++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 4c068f5bc5..551ca5daee 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -257,8 +257,12 @@ char *av_strireplace(const char *str, const char *from, const char *to) const char *av_basename(const char *path) { - char *p = strrchr(path, '/'); + char *p = NULL; + + if (!path || *path == '\0') + return "."; + p = strrchr(path, '/'); #if HAVE_DOS_PATHS char *q = strrchr(path, '\\'); char *d = strchr(path, ':'); @@ -274,11 +278,11 @@ const char *av_basename(const char *path) const char *av_dirname(char *path) { - char *p = strrchr(path, '/'); + char *p = path ? strrchr(path, '/') : NULL; #if HAVE_DOS_PATHS - char *q = strrchr(path, '\\'); - char *d = strchr(path, ':'); + char *q = path ? strrchr(path, '\\') : NULL; + char *d = path ? strchr(path, ':') : NULL; d = d ? d + 1 : d; diff --git a/libavutil/avstring.h b/libavutil/avstring.h index 37dd4e2da0..274335cfb9 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -274,16 +274,21 @@ char *av_strireplace(const char *str, const char *from, const char *to); /** * Thread safe basename. - * @param path the path, on DOS both \ and / are considered separators. + * @param path the string to parse, on DOS both \ and / are considered separators. * @return pointer to the basename substring. + * If path does not contain a slash, the function returns a copy of path. + * If path is a NULL pointer or points to an empty string, a pointer + * to a string "." is returned. */ const char *av_basename(const char *path); /** * Thread safe dirname. - * @param path the path, on DOS both \ and / are considered separators. - * @return the path with the separator replaced by the string terminator or ".". - * @note the function may change the input string. + * @param path the string to parse, on DOS both \ and / are considered separators. + * @return A pointer to a string that's the parent directory of path. + * If path is a NULL pointer or points to an empty string, a pointer + * to a string "." is returned. + * @note the function may modify the contents of the path, so copies should be passed. */ const char *av_dirname(char *path);