andmarti1424 / sc-im

sc-im - Spreadsheet Calculator Improvised -- An ncurses spreadsheet program for terminal
Other
4.77k stars 201 forks source link

Date Function Causes Segmentation Fault Crash #868

Open GitarMan opened 5 months ago

GitarMan commented 5 months ago

Version

I'm running version 0.8.4 built from source (because the latest version is not available yet in the apt-get repository, and I need multi-sheet functionality).

Segmentation Fault Crash

Specifically, I am experiencing the Segmentation Fault crash when I try to run the example date function from the documentation: \"@date(@now, "%d/%m/%Y")

I get the error: Segmentation fault (core dumped)

I ran sc-im with GNU Debugger to try to get a clue as to what could be causing the error. To be honest, I'm not too familiar with C programming / debugging, just thought it might help with the diagnosis.

Here was the output from gdb when I recreated the bug in an empty spreadsheet and then ran a backtrace:

[No Name]:{Sheet1}  A0 (10 2 0)                                                                                                                                                         -- INSERT --
Cannot rebuild graph with NULL ent
Program received signal SIGSEGV, Segmentation fault.     F         G         H         I         J         K         L         M         N         O         P         Q         R         S
 0                                                  0x000055555557b8ab in GraphAddVertex (graph=0x55555574c1b0, sh=0x55555574c240, ent=0x0) at graph.c:148
148                    (sh->id == graph->vertices->sheet->id && ent->row < graph->vertices->ent->row) ||
(gdb)
(gdb) backtrace
#0  0x000055555557b8ab in GraphAddVertex (graph=0x55555574c1b0, sh=0x55555574c240, ent=0x0) at graph.c:148
#1  0x0000555555582891 in eval (sh=0x55555574c240, ent=0x0, e=0x555555753e20, rebuild_graph=1) at interp.c:455
#2  0x00005555555839a4 in seval (sh=0x55555574c240, ent=0x55555572b010, se=0x5555557538b0, rebuild_graph=1) at interp.c:633
#3  0x00005555555863ce in slet (roman=0x55555574c1f0, sh=0x55555574c240, v=0x55555572b010, se=0x5555557538b0, flushdir=0) at interp.c:1633
#4  0x0000555555574128 in yyparse () at /home/ron/sc-im/src/gram.y:481
#5  0x00005555555a4402 in send_to_interp (oper=0x5555555d3340 <interp_line> L"label A0 = @date(@now, \"%d/%m/%Y\")") at cmds/cmds.c:1277
#6  0x00005555555a4312 in enter_cell_content (sh=0x55555574c240, r=0, c=0, submode=0x7fffffffb490 "label", content=0x7fffffff9490 L"@date(@now, \"%d/%m/%Y\")") at cmds/cmds.c:1255
#7  0x00005555555b14f0 in do_insertmode (sb=0x555555755820) at cmds/cmds_insert.c:213
#8  0x00005555555800b6 in exec_single_cmd (sb=0x555555755820) at input.c:341  sc-im - SpreadSheet Calculator Improvised
#9  0x0000555555580230 in exec_mult (buf=0x555555755820, timeout=177) at input.c:404 SC fork by Andrés Martinelli
#10 0x0000555555580188 in handle_mult (cmd_multiplier=0x5555555d2114 <cmd_multiplier>, buf=0x555555755820, timeout=177) at input.c:380
#11 0x000055555557fd16 in handle_input (buffer=0x555555755820) at input.c:214 Press  :help<Enter>  to get help
#12 0x000055555558b427 in main (argc=1, argv=0x7fffffffdb48) at main.c:339    Press  <Enter>       to enter NORMAL mode
(gdb)

General Date Functions Not Working

Less severe (because it doesn't cause a crash) is that when I try to run date functions in general, like: \"@hour("1708588800")

Or if I run: \"@now

I get the following error (without a crash): error in slet - exprerr

Thanks!

As a vim user, I am constantly frustrated when using any other spreadsheet program. I super appreciate this project.

There are just a few things missing for me to be able to completely replace programs like LibreOffice Calc. (Maybe I need to become more familiar with Lua to extend.) Would love better support for conditional formatting (I know about the CELL_NEGATIVE style). Worried about the crashes, so I have to save manually often.

But this is an awesome project! Thanks for all the effort you've put into it.

andmarti1424 commented 5 months ago

@GitarMan confirmed. will take a look at it.

andmarti1424 commented 5 months ago

@GitarMan Could you please update to latest commit on dev branch and retry? Thanks.

GitarMan commented 5 months ago

@andmarti1424 That fixed the segfault, thanks!!

Now when I run: \"@date(@now, "%Y/%m/%d")

It successfully outputs the date.

I tested some of the other date functions though, and and I'm still getting the error in slet - exprerr error (without a crash).

All these date functions are throwing that error: \"@tts(8,20,45) \"@now \"@year("1708588800") \"@month("1708588800") \"@day("1708588800") \"@hour("1708588800") \"@minute("1708588800") \"@second("1708588800")

However, this function works as expected: \"@date(@dts(1976, 12, 14))

andmarti1424 commented 4 months ago

@GitarMan hello. will check those commands. thank you.