Fix reading files with very long lines #12

Merged
merged 1 commit into from Nov 13, 2012

Projects

None yet

2 participants

@jjgod
Contributor
jjgod commented Nov 12, 2012

I hit this crash on Mac OS X while processing a file with 1 MB in only one line.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000100456000
0x00007fff82eb4337 in memmove$VARIANT$sse3x ()
(gdb) bt
#0  0x00007fff82eb4337 in memmove$VARIANT$sse3x ()
#1  0x00007fff82f2fe97 in fgets ()
#2  0x000000010000135d in convert (input_file=0x1001039a0
"/Users/jjgod/Downloads/昨日的世界/mobi7/z.html", output_file=0x1001000e0 "n.html", config_file=0x1001023f0 "zht2zhs.ini") at /Users/jjgod/Codes/cpp/OpenCC/src/tools/opencc.c:81
#3  0x000000010000176e in main (argc=7, argv=0x7fff5fbff920) at /Users/jjgod/Codes/cpp/OpenCC/src/tools/opencc.c:185

The solution I found is to avoid using the fragile fgets() and memory reallocation and replace it with simple fread() and fseek().

@jjgod jjgod Fix reading files with very long lines
I hit this crash on Mac OS X while processing a file with 1 MB in
only one line.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000100456000
0x00007fff82eb4337 in memmove$VARIANT$sse3x ()
(gdb) bt
 #0  0x00007fff82eb4337 in memmove$VARIANT$sse3x ()
 #1  0x00007fff82f2fe97 in fgets ()
 #2  0x000000010000135d in convert (input_file=0x1001039a0
 "/Users/jjgod/Downloads/昨日的世界/mobi7/z.html",
 output_file=0x1001000e0 "n.html", config_file=0x1001023f0 "zht2zhs.ini")
at /Users/jjgod/Codes/cpp/OpenCC/src/tools/opencc.c:81
 #3  0x000000010000176e in main (argc=7, argv=0x7fff5fbff920) at
/Users/jjgod/Codes/cpp/OpenCC/src/tools/opencc.c:185

The solution I found is to avoid using the fragile fgets() and
memory reallocation and replace it with simple fread() and fseek().
679dc91
@BYVoid BYVoid merged commit beb16b8 into BYVoid:master Nov 13, 2012
@jjgod jjgod referenced this pull request Jan 27, 2013
Merged

Typo and bug fix for reading #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment