issue on sizeof()

本文探讨了C语言中结构体的内存对齐问题,通过两个不同成员顺序的结构体示例,展示了成员变量的不同排列如何影响结构体的大小。通过对sizeof运算符结果的分析,可以帮助理解内存对齐原理及其对程序效率的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

 

 

 

sizeof(AType) 应该返回8还是返回5 ?

   5 = sizeof(char)+sizeof(int) = 1 + 4;

 

??????

 

static void check_hung_uninterruptible_tasks(unsigned long timeout) { int max_count = sysctl_hung_task_check_count; unsigned long last_break = jiffies; struct task_struct *g, *t; bool need_check = true; /* * If the system crashed already then all bets are off, * do not report extra hung tasks: */ 1. Condition test_taint(7), taking false branch. 2. Condition did_panic, taking false branch. if (test_taint(TAINT_DIE) || did_panic) return; hung_task_show_lock = false; rcu_read_lock(); 3. Condition 0 /* !((((sizeof (g->tasks.next) == sizeof (char) || sizeof (g->tasks.next) == sizeof (short)) || sizeof (g->tasks.next) == sizeof (int)) || sizeof (g->tasks.next) == sizeof (long)) || sizeof (g->tasks.next) == sizeof (long long)) */, taking false branch. 4. Switch case value 8. 49821: (#2 of 2): Out-of-bounds read (OVERRUN) overrun-local: Overrunning array of 1 bytes at byte offset 7 by dereferencing pointer (__u64 *)__u.__c. 这里为什么会有越界? CID 166846:MISRA C-2004 Control Statement Expressions (MISRA C-2004 Rule 13.1) [ "select issue" ] for_each_process_thread(g, t) { if (!max_count--) goto unlock; if (time_after(jiffies, last_break + HUNG_TASK_LOCK_BREAK)) { if (!rcu_lock_break(g, t)) goto unlock; last_break = jiffies; } trace_android_vh_check_uninterruptible_tasks(t, timeout, &need_check); if (need_check) /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ CID 49821:(#1 of 2):Out-of-bounds read (OVERRUN) [ "select issue" ] if (READ_ONCE(t->__state) == TASK_UNINTERRUPTIBLE) check_hung_task(t, timeout); } trace_android_vh_check_uninterruptible_tasks_dn(NULL); unlock: rcu_read_unlock(); if (hung_task_show_lock) debug_show_all_locks(); if (hung_task_show_all_bt) { hung_task_show_all_bt = false; trigger_all_cpu_backtrace(); } if (hung_task_call_panic) panic("hung_task: blocked tasks"); }
最新发布
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值