Mega Search
23.2 Million


Sign Up

Make a donation  
bug correction for the ccl.  
News Group: comp.lang.c

Hi

Ike Naar was kind enough to point me to two bugs in the CCL:

1) he said:

On 2014-08-21, jacob navia  wrote:
 > The C Containers library project aims to replicate most of the
 > functionality of C++ STL in C.
 > [...]
 > Download the ccl and enjoy.

I happened to notice a few oddities in strcollectiongen.c :

 > static size_t PopFront(ElementType *SC,CHAR_TYPE *buffer,size_t buflen)
 > {

[snip buggy code ]

 > }

 > First thing: according to the documentation, if buffer is NULL,
 > PopFront should remove the first element from the container without
 > copying it to the buffer, but in this implementation the container
 > is left unmodified when buffer is NULL (the function just returns
 > early).

Right.

The reason for this bug is an update of the documentation without an 
update of the code. Shame on me!


 > A minor point: in

 >     memcpy(buffer,result,tocopy);
 >     buffer[tocopy-1] = 0;

 > the count in the memcpy call could be tocopy-1, as buffer[tocopy-1]
 > is immediately overwritten with 0 after the memcpy call.

Yes, the correction should be
static size_t PopFront(ElementType *SC,CHAR_TYPE *buffer,size_t buflen)
// .......
  774     if (buffer) {
  775         tocopy = len;
  776         if (buflen < tocopy)
  777             tocopy = buflen-1;
  778         memcpy(buffer,result,tocopy);
  779         buffer[tocopy] = 0;
  780     }

 > All issues apply to PopBack as well as to PopFront.


Corrected also!

 > Just out of curiosity, what is the purpose of the cast in situations 
 > like

 >   r = DuplicateString(SC,newval,(char *)"ReplaceAt");

?

Well, for some compilers, immediate character strings are considered 
const, then they will complain about that when theb strings are passed 
to a function that receives a non const parameter.

As far as I remember...

Thanks for your help.


Vote for best question.
Score: 0  # Vote:  0
Date Posted: 27-Aug-2014, at 2:31 PM EST
From: jacob navia