From 7125e7bebd512a24427a7971ac1aff9acbae8668 Mon Sep 17 00:00:00 2001 From: ricky <67306039+illustriousness@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:07:57 +0800 Subject: [PATCH] include:rtdef.h: comment Refine the annotation of RT_ALIGN and RT_ALIGN_DOWN (#10201) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit include :rtdef.h : [ Refine the annotation of RT_ALIGN and RT_ALIGN_DOWN ] This macro is vulnerable to non-2-byte alignments, but I assume that the macro definition was designed with an explicit use case of 2-byte alignments in mind. Therefore, I only modify the comment to remind the user. Solution: RT_ALIGN(size, align) ((size) + (align) - 1) / (align) * (align) RT_ALIGN_DOWN(size, align) (size) / (align) * (align) Here's what deepseek recommends more. Signed-off-by: Yucai Liu <1486344514@qq.com> --- include/rtdef.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/rtdef.h b/include/rtdef.h index 99ce5992d4..401a47be27 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -251,6 +251,7 @@ typedef int (*init_fn_t)(void); * @def RT_ALIGN(size, align) * Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4) * would return 16. + * @note align Must be an integer power of 2 or the result will be incorrect */ #define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1)) @@ -260,6 +261,7 @@ typedef int (*init_fn_t)(void); * @def RT_ALIGN_DOWN(size, align) * Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4) * would return 12. + * @note align Must be an integer power of 2 or the result will be incorrect */ #define RT_ALIGN_DOWN(size, align) ((size) & ~((align) - 1))