Re: [anjuta-devel] Clang and the include files



Hi Moritz!

At the moment I fight against segmentation fault. For unknown reasons 
clang_getLocationForOffset () fails sometimes [1]. Maybe I forgot to 
allocate something?

Don't know the exact reason but a couple of things come into my mind:

if (unsavedContent)
{
        DEBUG_PRINT ("Reparse code with unsaved content.");
        numUnsaved = 1;
        // use unsaved = g_new0(CXUnsavedFile, 2) instead
        unsaved = g_malloc (2 * sizeof (struct CXUnsavedFile));
        unsaved[0].Filename = assist->priv->editor_filename;
        unsaved[0].Contents = unsavedContent;
        // Are you sure you need the utf8 length? That gives you the number of
characters but not the number of bytes allocated. I am quite sure you
need strlen() here. This could be the reason for the segmentation fault
        unsaved[0].Length = g_utf8_strlen (unsavedContent, -1);
        // Any reason to do this? Anyway, with g_new0 you won't have to because
all memory will be initialized with NULL.
        unsaved[1].Filename = NULL;
        unsaved[1].Contents = NULL;
        unsaved[1].Length = 0;
}

const gchar* unsavedContent = ianjuta_editor_get_text_all (
        IANJUTA_EDITOR (assist->priv->iassist), NULL);

The return value here is non-const, you will need to free that data at
some point (when destroying the unsaved[] structure for example).

If you don't find a solution, try to create a simple test program that
you can run with valgrind. You can run anjuta in valgrind but it's damn
slow - it gives good results usually though.

Regards,
Johannes

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]