Hi all,

I'm in the middle of building on the Icecast2 RLM to hook up a website 
and Live 365.  I'm in the early learning phases so just trying to get my 
head around the existing code.

In rlm_icecast2.c the function void rlm_icecast2_RLMStart(void 
*ptr,const char *arg) has several lines that look like this for 
different variables:

rlm_icecast2_usernames=realloc(rlm_icecast2_usernames,
                           (rlm_icecast2_devs+1)*(rlm_icecast2_devs+1)*256);

My C is frankly very poor so I'm putting money on I've missed something 
obvious rather than a code error so if someone can help my understanding 
it would be useful.

So far heres what I've got, we're inside a loop where rlm_icecast2_devs 
starts at 0 and gets incremented for each Icecast server you're pushing 
to.

So this line is just reallocating memory to grow rlm_icecast2_usernames 
to fit the next username in the config file.

Heres where it gets strange, usernames are 256 byte character arrays.  
So if we have 1 username we need 256 bytes, 2; 512 etc.

But the line is doing some strange squaring:

(rlm_icecast2_devs+1)*(rlm_icecast2_devs+1)*256

So if I've read this right this is what we're getting:

Loop 0: rlm_icecast2_usernames = 256 Bytes (1 * 1 * 256)
Loop 1: rlm_icecast2_usernames = 1024 Bytes (2 * 2 * 256)
Loop 2: rlm_icecast2_usernames = 4096 Bytes (4 * 4 * 256)

Loop 1 is 512 bytes bigger than it needs to be, Loop 2 3328 bytes 
bigger.

If the square wasn't there it would make sense (1 * 256, 2 * 256, 3 * 
256 etc).

What makes it more confusing is that after this realloc, we're copying 
the new usernames into the variable but in the place you'd expect to 
copy e.g.:

Loop 0: strcpy(0, username)
Loop 1: strcpy(256, username)
Loop 2: strcpy(512, username)

What am I missing here?

Regards,

Wayne
_______________________________________________
Rivendell-dev mailing list
[email protected]
http://lists.rivendellaudio.org/mailman/listinfo/rivendell-dev

Reply via email to