BYVoid/OpenCC — pull request #12 by jjgod (2012-11-12 23:06:42+00:00)
Title: 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()`.