Skip to content

Commit 7125e7b

Browse files
include:rtdef.h: comment Refine the annotation of RT_ALIGN and RT_ALIGN_DOWN (#10201)
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 <[email protected]>
1 parent 443c530 commit 7125e7b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

include/rtdef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ typedef int (*init_fn_t)(void);
251251
* @def RT_ALIGN(size, align)
252252
* Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
253253
* would return 16.
254+
* @note align Must be an integer power of 2 or the result will be incorrect
254255
*/
255256
#define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1))
256257

@@ -260,6 +261,7 @@ typedef int (*init_fn_t)(void);
260261
* @def RT_ALIGN_DOWN(size, align)
261262
* Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4)
262263
* would return 12.
264+
* @note align Must be an integer power of 2 or the result will be incorrect
263265
*/
264266
#define RT_ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
265267

0 commit comments

Comments
 (0)