From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 770AC407D8 for ; Fri, 1 Apr 2022 17:05:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 62EF868B107; Fri, 1 Apr 2022 20:05:53 +0300 (EEST) Received: from out203-205-221-149.mail.qq.com (out203-205-221-149.mail.qq.com [203.205.221.149]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A70968B0AD for ; Fri, 1 Apr 2022 20:05:45 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1648832741; bh=q64e9aHBQXiOP8els3eWU0/SJOjSicGBLYvstfk9lXo=; h=From:To:Cc:Subject:Date; b=LkveEkisCU+LbeT64T8kENbuc/vKBh9fdCp8/ezdELlFM8BbVBWTKpL0X9+mxsXXN kZdYDxtluZfYIK/g9Es2PsYbTYih4DVEl4cESpYHJsoaA6+Htp7QLoqAoq/y6YfiFG 1UDnVbKfX2xtQ847dzr5WXczfU+64MogVOsG5Oqw= Received: from ZHILIZHAO-MB2.tencent.com ([113.87.131.31]) by newxmesmtplogicsvrszb6.qq.com (NewEsmtp) with SMTP id 16795A61; Sat, 02 Apr 2022 01:05:39 +0800 X-QQ-mid: xmsmtpt1648832739tvl2vc123 Message-ID: X-QQ-XMAILINFO: Ncpnai4dwVTHcSjZpetIxaVcqNz90UR2hOV2a/JNjNv/7H74ktq9MrVeruzYoX nvOVzzXfR4d4ldxcqSb2MeKt0j9GFddHZS0UlbAYwOOBn7j9314fqa1moB913rhu1iMDoOzbzknk WHkLBizr/DVtSwZ1GPT4EBMT9jaOpO9RGkC4b0xPcTfpLXV5sWoPm9dlCEwzwUFuRsVP7GmanElF ZozDNuK3CjB7OJpWqWSiXKv86g2e6pEyhD5nvtiDXc/FStFBpMrWTBJ+MeZhDX2CUSa7i+DwwPL3 OPEH13k1vuwzzhdFwSxEN5wgQNJsXYG4Z0lXrPxHdO+YdfQq7pwwzdC9/YoElKWVQ1QQgy1aYqzm izbgQ7VF544+dRAbmGuYEZD7rLWxBM4AKQTCF4hXg7cYVn+6GNFu7+vuwDl14b4qU0rmVeVO9pNj H/loYwivDjgQam2MfV0rVnGRRPzj9+Uy/A1wXOdiHyg3a/0uoYXKEkxo6OJlTvRDx8AoOT+c/k9N yn62xLclSOGkOaBx6cR33RrvwjVwzPlhJImREpiWhvEW/DzTx+8uGVunxzXUZsGCE37mNa7JExr1 er9qjX/prpO5kV4+owMbTOKHqKD8YAmBFSSTZyAbsVLtPIhg1r6hqkQ7ZkW0XwW3oNqOHHwiTWCr nu1qaH95u4R2ouifD9yoZJhxGshKBWsr3YjMXjpp/4WEk65T1wqWgnfeHhA5Qh0wVZiBUOjimS5+ W2gmqGsyh01PgV08R0E7UjgsBJz2IpIH8gfSkbWLlcu7vfLHlP6q7vwdw+M9igiKK75+aqOzwpRh USlYw81956CTIVe62y40hK+Yv6bV+KjXC+VOUpmFF/4f6ZPyABj8O6gtgwMDCvHL8Ddqr08TbltL FxUoYfRzDiJNavbCnr34kW4UYf+OA7nEw9pM1+wQRDIE+hd/49wfM6vZSFp/TjPv56cwozMcNo From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 Apr 2022 01:05:37 +0800 X-OQ-MSGID: <20220401170537.13072-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avutil/mem: fix doc for reallocs X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: The doc says those function are like av_free if size or nmemb is zero. It doesn't match the code. av_realloc() realloc one byte if size is zero, which was added by 91ff05f6ac5 ten years ago. realloc() itself in C is implementation-dependent. Make the doc match the longstanding behaviour. --- libavutil/mem.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libavutil/mem.h b/libavutil/mem.h index b9fe80738c..d91174196c 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -250,8 +250,7 @@ void *av_mallocz_array(size_t nmemb, size_t size) av_malloc_attrib av_alloc_size /** * Allocate, reallocate, or free a block of memory. * - * If `ptr` is `NULL` and `size` > 0, allocate a new block. If `size` is - * zero, free the memory block pointed to by `ptr`. Otherwise, expand or + * If `ptr` is `NULL` and `size` > 0, allocate a new block. Otherwise, expand or * shrink that block of memory according to `size`. * * @param ptr Pointer to a memory block already allocated with @@ -260,10 +259,11 @@ void *av_mallocz_array(size_t nmemb, size_t size) av_malloc_attrib av_alloc_size * reallocated * * @return Pointer to a newly-reallocated block or `NULL` if the block - * cannot be reallocated or the function is used to free the memory block + * cannot be reallocated * * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be - * correctly aligned. + * correctly aligned. The returned pointer must be freed after even + * if size is zero. * @see av_fast_realloc() * @see av_reallocp() */ @@ -311,8 +311,7 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize); /** * Allocate, reallocate, or free an array. * - * If `ptr` is `NULL` and `nmemb` > 0, allocate a new block. If - * `nmemb` is zero, free the memory block pointed to by `ptr`. + * If `ptr` is `NULL` and `nmemb` > 0, allocate a new block. * * @param ptr Pointer to a memory block already allocated with * av_realloc() or `NULL` @@ -320,19 +319,19 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize); * @param size Size of the single element of the array * * @return Pointer to a newly-reallocated block or NULL if the block - * cannot be reallocated or the function is used to free the memory block + * cannot be reallocated * * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be - * correctly aligned. + * correctly aligned. The returned pointer must be freed after even if + * nmemb is zero. * @see av_reallocp_array() */ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size); /** - * Allocate, reallocate, or free an array through a pointer to a pointer. + * Allocate, reallocate an array through a pointer to a pointer. * - * If `*ptr` is `NULL` and `nmemb` > 0, allocate a new block. If `nmemb` is - * zero, free the memory block pointed to by `*ptr`. + * If `*ptr` is `NULL` and `nmemb` > 0, allocate a new block. * * @param[in,out] ptr Pointer to a pointer to a memory block already * allocated with av_realloc(), or a pointer to `NULL`. @@ -343,7 +342,7 @@ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size) * @return Zero on success, an AVERROR error code on failure * * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be - * correctly aligned. + * correctly aligned. *ptr must be freed after even if nmemb is zero. */ int av_reallocp_array(void *ptr, size_t nmemb, size_t size); -- 2.31.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".