任务单 #47831

AI: adjust_improvement_wants_by_effects() mypreq NULL dereference

开放日期: 2023-04-10 14:09 最后更新: 2023-04-22 12:36

报告人:
属主:
类型:
状态:
关闭
组件:
里程碑:
优先:
5 - Medium
严重性:
5 - Medium
处理结果:
Fixed
文件:
2

Details

Clang analyzer:

---
../../../../src/ai/default/daicity.c:1720:61: warning: Access to field 'range' results in a dereference of a null pointer (loaded from variable 'mypreq') [core.NullDereference]
                                     turns, peffect, cities[mypreq->range],
                                                            ^~~~~~~~~~~~~
---

That seems a real bug. 'mypreq' is set only when there's a requirement related to the improvement in question, and the above line can be executed even when there is no such requirement.

任务单历史 (3/6 Histories)

2023-04-10 14:09 Updated by: cazfi
  • New Ticket "AI: adjust_improvement_wants_by_effects() mypreq NULL dereference" created
2023-04-10 14:18 Updated by: cazfi
评论

Reply To cazfi

That seems a real bug.

Or maybe not:

 effect_list_iterate(get_req_source_effects(&source), peffect) {
 ...
     requirement_vector_iterate(&peffect->reqs, preq) {
     ...
      if (universal_fulfills_requirement(preq, &source) == ITF_YES) {
        mypreq = preq;

Iterating only 'get_req_source_effects(&source)' effects should guarantee that there is a requirement matching 'universal_fulfills_requirement(preq, &source)'

2023-04-14 09:02 Updated by: cazfi
  • 属主 Update from (无) to cazfi
  • 处理结果 Update from to Accepted
  • 里程碑 Update from (无) to 3.0.8 (关闭)
评论

Reply To cazfi

Iterating only 'get_req_source_effects(&source)' effects should guarantee that there is a requirement matching 'universal_fulfills_requirement(preq, &source)'

However, despite the reported problem not being there, the "opposite" is. The assumption of exactly one requirement fulfilled by the building breaks the case when the building actually provides solution to multiple requirements (feasible esp. in S3_2/main with the BuildingFlag requirement type). Easy fix to avoid the "exactly one requirement fulfilled" assumption, fixing both the actual bug and the (false positive) warning attached.

2023-04-22 12:36 Updated by: cazfi
  • 状态 Update from 开启 to 关闭
  • 处理结果 Update from Accepted to Fixed

编辑

Please login to add comment to this ticket » 登录名