GithubHelp home page GithubHelp logo

Seg Fault about kilo HOT 4 OPEN

a-p-jo avatar a-p-jo commented on July 22, 2024
Seg Fault

from kilo.

Comments (4)

 avatar commented on July 22, 2024 2

Ahh, yes I see the problem! You're on a Crapple platform. Crapple only supports what they think their users want. Consider Windows or Linux in the near future.

from kilo.

a-p-jo avatar a-p-jo commented on July 22, 2024 1

@antirez and any other maintainers here, please note :

Summary

When opening clip.c in kilo, it segfaults at the 90th line.

The origin of this failure is in the order :

In main() , at editorOpen(argv[1]); 's while((linelen = getline(&line,&linecap,fp)) != -1) {...} at it's 90th iteration, at function editorInsertRow(E.numrows,line,linelen); , in which it crashes at call editorUpdateSyntax(row); Where, there is a while(*p){...} inside which the segfault occurs at memset(row->hl+i,HL_COMMENT,row->size-i); After *p is the first / in // comment

The 90th line :

				if(fclose(to)) // Close this clipboard

Structure of line : \t\t\t\tif(fclose(to)) // Close this clipboard\n , i.e., 4 \t level of indentation.

Please see what's up with memset() and what it's doing

from kilo.

a-p-jo avatar a-p-jo commented on July 22, 2024

Changed main() to be such :

int main(int argc, char **argv) {
    if (argc != 2) {
        fprintf(stderr,"Usage: kilo <filename>\n");
        exit(1);
    }

    fprintf(stderr, "1.Got Arguments, checked them.\n2.Initing... ");
    initEditor();
    fprintf(stderr, "Inited\n3.Sending filename to select syntax highlighting... ");
    editorSelectSyntaxHighlight(argv[1]);
    fprintf(stderr, "Sent\n4.Opening editor with filename ... ");
    editorOpen(argv[1]);
    fprintf(stderr, "Opened\n5.Enabling raw mode on stdin... ");
    enableRawMode(STDIN_FILENO);
    fprintf(stderr, "Enabled\n6.Setting status message... ");
    editorSetStatusMessage(
        "HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find");
    fprintf(stderr, "Set\n7. Begining loop of editor... ");
    while(1) {
        editorRefreshScreen();
        editorProcessKeypress(STDIN_FILENO);
    }
    return 0;
}

Printf debugging :)

Ran kilo clip.c 2> err.txt

Ran cat err.txt after segmentation fault message :

1.Got Arguments, checked them.
2.Initing... Inited
3.Sending filename to select syntax highlighting... Sent
4.Opening editor with filename ...

Error lies somewhere in editorOpen(argv[1]);

EDIT 1 :
In editorOpen(argv[1]);

There is a while((linelen = getline(&line,&linecap,fp)) != -1) {...}

Things were working till there, but not after.

So I ran a loop counter uint64_t i = 0; inside it, and wrote to stderr it's count.

It crashes at 90th iteration , when clip.c has the line :
if(fclose(to)) // Close this clipboard

More printing shows that in the 90th iteration , the while loop starts , but crashes in
editorInsertRow(E.numrows,line,linelen);

Edit 2:

At the 90th line , the values being sent to editorInsertRow(...) seem okay :

E.numrows = 89
line = 				if(fclose(to)) // Close this clipboard
linelen = 42   

Edit 3:
At the 90th line, inside editorInsertRow(...) , it crashes at editorUpdateRow(E.row+at);

Edit 4:
This is getting quite tiring. Nearly every function I see is using malloc(...) , realloc(...) and such and running with the returned pointers without checking for NULL !!!

Edit 5:
Continuing from 3, it seems editorUpdateSyntax(row); is failing at the 90th line
It appears to segfault at the 90th line's comment's second / , like :

if(fclose(to)) // Close this clipboard
~~~~~~~~~~~~~~^(segfaults here)

EDIT 6: Found it !

Looking in detail, in particular investigating the while(*p){...} loop that handles characters, in :

/* Handle // comments. */
        if (prev_sep && *p == scs[0] && *(p+1) == scs[1]) {...}

The memset(row->hl+i,HL_COMMENT,row->size-i); is causing a segfault.

from kilo.

CakesStuff avatar CakesStuff commented on July 22, 2024

memset(row->hl+i,HL_COMMENT,row->size-i);
should be:
memset(row->hl+i,HL_COMMENT,row->rsize-i);

Edit: also causes problems on linux.

from kilo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.