bugFreeciv - Bugs: bug #19104, [traits] in sanity_check_size()...

Show feedback again

bug #19104: [traits] in sanity_check_size() [mem.c::61]: Warning: malloc with size 0

Submitted by:  Jacob Nevins <jtn>
Submitted on:  Sat Dec 3 18:11:10 2011  
Category: generalSeverity: 3 - Normal
Priority: 5 - NormalStatus: Fixed
Assigned to: Jacob Nevins <jtn>Open/Closed: Closed
Release: Operating System: Any
Planned Release: 2.5.0Contains string changes: None

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


Tue Dec 6 22:16:36 2011, SVN revision 20636:

Fix off-by-one when allocating space for nation traits.

See gna bug #19104.

(Browse SVN revision 20636)

Jacob Nevins <jtn>
Project AdministratorIn charge of this item.
Sat Dec 3 18:31:05 2011, comment #1:

On second thoughts, let's use fc_calloc(). We don't need the zeroing, but otherwise it's tidier.

(file #14641)

Jacob Nevins <jtn>
Project AdministratorIn charge of this item.
Sat Dec 3 18:11:10 2011, original submission:

Running a trunk server with "-d 3" gives a bunch of the quoted message.

This is due to an off-by-one when malloc'ing space for nation traits (there's currently one, "placeholder", but we malloc k*trait_max() where trait_max() is 0).

This presumably doesn't lead to segfaults because fc_real_malloc() suppresses the allowed/common C behaviour of returning NULL from malloc(0) (although it's still malloc'ing only 1 char, not sizeof(int)).

Jacob Nevins <jtn>
Project AdministratorIn charge of this item.


(Note: upload size limit is set to 1024 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #14641:  trunk-trait-nation-alloc-bis.diff added by jtn (744B - text/x-patch - trunk r20621 -- use fc_calloc())
file #14640:  trunk-trait-nation-alloc.diff added by jtn (747B - text/x-patch - trunk r20621)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by jtn (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Error: not logged in



    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue Dec 6 22:18:37 2011jtnStatusReady For Test=>Fixed
    Sat Dec 3 18:31:05 2011jtnAttached File-=>Added trunk-trait-nation-alloc-bis.diff, #14641
    Sat Dec 3 18:12:06 2011jtnAttached File-=>Added trunk-trait-nation-alloc.diff, #14640
      StatusIn Progress=>Ready For Test
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup