Comments (4)
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.
@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.
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.
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)
- Heap buffer overflow in kilo's editor_update_syntax(…) HOT 7
- How to support python highlight? HOT 1
- Question: Why kilo allocating 9 bytes memory for a non-printable character? HOT 2
- Use smcup and rmcup to save/restore screen buffer HOT 1
- Status screen not refreshing upon closing HOT 1
- Weird cursor behaviour when non-English characters are typed HOT 1
- Why does it work HOT 3
- compiler warnings HOT 3
- How can I debug the program using GDB? HOT 1
- Integer Overflow && heap-buffer-overflow in kilo.c HOT 2
- /usr/include/features.h:185:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp] HOT 2
- ‘UINT32_MAX’ undeclared problem in Linux HOT 1
- getCursorPosition sometimes fails and sometimes it works but ...
- [Documentation] Tutorial? HOT 1
- use on Windows? HOT 4
- Clang Warnings HOT 1
- License HOT 1
- Syntax Highlighting Segfault HOT 1
- Segfault at if '\<letter>' entered inside string & if compiled with musl-gcc (a proposed fix is also included)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kilo.