Project

General

Profile

Actions

Bug #1676

open

hitpoints = 0 in units.ruleset causes divide by 0 crash

Added by Dean Brown about 2 months ago. Updated 8 days ago.

Status:
In Review
Priority:
Normal
Category:
Server
Target version:
Start date:
09/08/2025
Due date:
% Done:

0%

Estimated time:

Description

Careless rule set hacking strikes again, but there's nothing warning you not to set hitpoints = 0 in units.ruleset, and the ruleset loads OK.

In tilespec.c routine fill_unit_sprite_array()

  ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / ptype->hp;


Files

1676_S3_2.patch (4.36 KB) 1676_S3_2.patch Dean Brown, 10/19/2025 02:31 AM
1676_S3_3.patch (4.41 KB) 1676_S3_3.patch Dean Brown, 10/22/2025 04:48 AM
1676_Main.patch (4.41 KB) 1676_Main.patch Dean Brown, 10/22/2025 04:51 AM
Actions #1

Updated by Dean Brown about 2 months ago

  • File 1676.patch added

Patch should be good for all branches.

Actions #2

Updated by Marko Lindqvist about 2 months ago

That's unlikely to be the only place where such a zombie (unit dies when it reach 0 HP) causes problems. The fix should be in ruleset sanity checking.

Actions #3

Updated by Marko Lindqvist about 2 months ago

secfile_lookup_int_default_min_max() would be your friend.

Actions #4

Updated by Dean Brown about 2 months ago

  • File deleted (1676.patch)
Actions #5

Updated by Dean Brown about 2 months ago

  • File 1676_S3_2.patch added
  • File 1676_S3_3_Main.patch added

Agree, better to fix the cause instead of the symptom.

Actions #6

Updated by Marko Lindqvist about 2 months ago

For rulesets that play excessively with better firepower and hitpoints as game progresses, maximum hp of 100 is rather low upper limit, especially in S3_2 where we should not break any existing rulesets (d3f). I'd say 10000 would be safe value even as such absolute maximum.

Actions #7

Updated by Dean Brown about 2 months ago

  • File deleted (1676_S3_2.patch)
Actions #8

Updated by Dean Brown about 2 months ago

  • File deleted (1676_S3_3_Main.patch)
Actions #9

Updated by Dean Brown about 2 months ago

  • File 1676_S3_2.patch added
  • File 1676_S3_3_Main.patch added

I wasn't sure about what max value to set, thanks for the suggestion. Updated the patches.

Actions #10

Updated by Marko Lindqvist about 1 month ago

  • Category changed from client-common to Server
  • Target version set to 3.2.2
Actions #11

Updated by Marko Lindqvist 20 days ago

You should also make it impossible to set hitpoints to zero (or other illegal value) from the ruledit. Otherwise one may accidentally changes hitpoints to zero, saves the ruleset, and the ruleset load time check makes it impossible to load ruleset back in for fixing the situation.

Actions #12

Updated by Dean Brown 18 days ago

  • File 1676_ruledit.patch added

Good point. Turns out there's already code to set limits, just need to change the min value from 0 to 1.

1676_ruledit.patch good for all branches.

Actions #13

Updated by Marko Lindqvist 13 days ago

We don't want to knowingly introduce the bug in the git history, and only separately fix it. Please combine ruledit change with the rest of the patch (single patch for each branch)

Actions #14

Updated by Dean Brown 12 days ago

  • File deleted (1676_ruledit.patch)
Actions #15

Updated by Dean Brown 12 days ago

  • File deleted (1676_S3_3_Main.patch)
Actions #16

Updated by Dean Brown 12 days ago

  • File deleted (1676_S3_2.patch)
Actions #17

Updated by Dean Brown 12 days ago

No problem.

Actions #18

Updated by Marko Lindqvist 10 days ago

The patch does not apply to main branch. The same patch does apply for S3_3, so I guess you just need a separate patch for main.

Actions #19

Updated by Dean Brown 9 days ago

  • File deleted (1676_S3_3_Main.patch)
Actions #21

Updated by Marko Lindqvist 8 days ago

  • Status changed from New to In Review
  • Assignee set to Marko Lindqvist
Actions

Also available in: Atom PDF