On Mon, Aug 30, 2004 at 10:07:13PM +0200, Thomas Pfeiffer wrote:
>  PRUint32 *newcount = 0;

I don't think you want this to be a pointer. Instead, use:
  PRUint32 newcount = 0;

>  char *entry = "foobar" + '\0';

I'm puzzled why you are doing a + '\0' here... all string literals have
a terminating NUL in C and C++, and + does not do what you seem to think
with char*.

>  for(PRUint32 i = 0; i < *count; i++)
>  {
>   int len = strlen(entry);
>   outArray[i] = (char*)nsMemory::Alloc(len * sizeof(char) + 1);
>   outArray[i] = entry;

You need to copy the string:
  strcpy(outArray[i], entry);

This is another reason for a crash (after this fcn returns)

>   *newcount = i;

This is where you were crashing, because you carefully inited newcount
to be a NULL pointer.

>  }
> 
>  *valueData = outArray;
>  *count = *newcount;

So, with the PRUint32 suggestion, this would become:
  *count = newcount;

> 
>  return NS_OK;
> }
> 
> I've read about ADDREF,

Not an issue here since no objects are passed anywhere.

> but don't know how to use it. - But it seems like
> there's an issue with memory access in the above. It runs through,

It _runs through_?? *newcount = i; must have crashed. Unless your
compiler took the liberty of optimizing away that variable entirely,
maybe? (since *count is effectively unchanged by your code)

> And I've read about using the event-queue and callbacks for such
> communication, but would prefer the above approach if possible.

If you are not using threads, you need not bother with event queues,
most likely.

-- 
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to