This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Increasing the size of an array (realloc)

0

Can you use realloc to resize an array? or do i have to do it the manual way??. At the moment realloc crashes wireshark but i may be using incorrectly

asked 05 Feb '13, 19:55

StealthUE's gravatar image

StealthUE
667713
accept rate: 100%


One Answer:

1

What do you mean by "array"? A C array defined as, say int foo[20] cannot be resized at all. C99 supports variable-length arrays, as do pre-C99 versions of GCC, but those arrays aren't resizable - the size is fixed at the time the array is allocated.

If you use malloc() to allocate an array at run time, you can use realloc() to resize it. If that's crashing, you might be using it wrong.

answered 05 Feb '13, 20:21

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196
accept rate: 19%