Opened 18 years ago

Closed 18 years ago

#1539 closed defect (fixed)

Problem with symbols of Type = ellipse and Style is over 105

Reported by: dmorissette Owned by: dmorissette
Priority: high Milestone: 4.8 release
Component: MapServer C Library Version: unspecified
Severity: normal Keywords:
Cc:

Description

Mathieu Bertrand wrote:

> Hi,
>
> just to follow my tought of yesterday, here is the code to dynamically
> allocate space to the array:
>
> ------
>   int numElemStyle=0;
>   for(z=0; z<symbol->stylelength; z++)
>   {
>     numElemStyle = numElemStyle + symbol->style[z];
>   }
>   styleDashed = (int *)calloc(numElemStyle, sizeof(int));
> -----------
>
> It could be put immediately after "symbol =
> &(symbolset->symbol[style->symbol]);" (around line 1620) in mapgd.c
>
> Also, don't forget to put a "free(styleDashed);" before each return in
> the function. (To prevent memory leak)
>
> Any comment will be welcome.
>
> I'm receiving message from MAPSERVER-DEV often a long time after they
> were posted.  Is there any reason to that ? (Example : I didn't yet
> receive the message I post yesterday afternoon)
>
> Thank you,
> -Mathieu Bertrand
>
>
>
>
>
>
> On 11/11/05, Mathieu Bertrand <mjbertrand@gmail.com> wrote:
>
>> Hi,
>>
>> I have a mapfile declaring a symbol like this one :
>> ------
>> SYMBOL
>>  NAME 'test'
>>  TYPE ELLIPSE
>>  POINTS 1 1 END
>>  FILLED true
>>  STYLE
>>        50 56
>>  END
>> END
>> ------
>>
>> With that symbol, mapserver always crash.
>> However, if I set the following STYLE, it don't crash :
>> STYLE
>>   50 55
>> END
>>
>> I scan through the code and the error come from mapgd.c, in the
>> function "msDrawLineSymbolGD".  Nearly at the end of the function,
>> there is the following code :
>> ---
>>    int k=0, sc;
>>
>>    sc = fc; /* start with foreground color */
>>    for(i=0; i<symbol->stylelength; i++)
>>    {
>>      for(j=0; j<symbol->style[i]; j++)
>>      {
>>        styleDashed[k] = sc;
>>        k++;
>>      }
>>      if(sc==fc) sc = bc;
>>      else sc = fc;
>>
>>    }
>> ----
>> (format may differ)
>>
>> Problem is because styleDashed is declare : "int styleDashed[100];"
>>
>> I don't know why it work for k = 105 (style 50 55)  when the array is
>> declare to be 100 elements, but it crash when k = 106.
>>
>> I declared the array to 200 elements and mapserver didn't crash.
>>
>> Is anybody know why that array was declared to be only 100 elements.
>>
>> I'm not a pro in c programming, but I'm pretty sure that there is a
>> way to allocate space in the array dynamically depending on the style
>> declaration of the mapfile with malloc.  Is there any reason why it
>> was not implemented with malloc at the beggining ?
>>
>> Thank you,
>> -Mathieu Bertrand
>>
>
>
>

Change History (5)

comment:1 by dmorissette, 18 years ago

Status: newassigned

comment:2 by dmorissette, 18 years ago

Cc: steve.lime@… added
Steve, I was going to remove the use of MS_MAXPATTERNSIZE to use dynamic
allocation in both msDrawLineSymbolGD() and msCircleDrawLineSymbolGD(), but then
I saw that you added MS_MAXPATTERNSIZE to mapsymbol.h only a few weeks ago. Is
it okay with you if we remove it and switch to dynamic allocation?

comment:3 by dmorissette, 18 years ago

Milestone: 4.8 release

comment:4 by dmorissette, 18 years ago

I verified that a copy of the style array is made by gdImageSetStyle() so it is
safe to free the array just after the call:

http://www.boutell.com/gd/manual2.0.33.html#gdImageSetStyle

comment:5 by dmorissette, 18 years ago

Resolution: fixed
Status: assignedclosed
I was unable to reproduce the crash with 47, there was a 'break' added in the
loop . However I did get the crash with 4.6.

Anyway, I have replaced the styleDashed[MS_MAXPATTERNSIZE] with a dynamically
allocated array in both msDrawLineSymbolGD() and msCircleDrawLineSymbolGD(). 

This will be in 4.8beta2.

Marking fixed.
Note: See TracTickets for help on using tickets.