Menu

Code review and testing for C data structures project

Andrei
2016-10-15
2017-01-19
  • Andrei

    Andrei - 2016-10-15

    Hello. The "ctnr" project tries to mimic the functionality of C++ containers for C programmers (more specifically C99).

    The work is at the very early stages and I need feedback to fix bugs and iron out design mistakes, before they become unfixable.

    https://sourceforge.net/projects/ctnr/

    To give you a better idea what the project is about, here's a code example for ctnr/dynarray.h:

    #include <stdio.h>
    #include "ctnr/dynarray.h"
    
    int main(void)
    {
        dynarray(int) dai;
    
        if (dynarray_create(dai, 3))
        {
            dynarray_ptrcopy(dai, ((const int []){10, 20, 30, 40}), 4);
            printf("Size: %zu, Capacity: %zu\n",
                dynarray_size(dai), dynarray_capacity(dai));
            printf("Contents: ");
    
            for (dynarrayiter(dai) it = dynarrayiter_begin(dai);
                it != dynarrayiter_end(dai);
                dynarrayiter_inc(it))
            {
                printf("%d ", dynarrayiter_deref(it));
            }
    
            printf("\nElement at index 2: %d\n", dynarray_at(dai, 2));
            dynarray_destroy(dai);
        }
    }
    
     
  • Xingming Wu

    Xingming Wu - 2017-01-19

    Dear Andrei,
    I detect a NULL pointer dereference bug in file “test_dlistiter_inc.c” by our static analysis tool. Actually, it is a bug from you test code instead of the data structure you elaborately designed.
    The detail of the bug is introduced as a bug report in the attachment “NULL-pointer-dereference.png”. The bug report lists where the bug shall happen and why it happens. If the code runs as the path we highlighted in the bug report, the bug will be triggered.
    When you confirm the report, there is a non-trivial macro “dlist_ptrcopy” in the source code, and we extend it in the second attachment, which might help.

     

    Last edit: Xingming Wu 2017-01-19

Log in to post a comment.