ctelroy / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

Crash when creating FileStream from empty file #77

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create an empty file
2. obtain a FILE* to it
3. create a rapidjson::FileStream on this

What is the expected output? What do you see instead?

Expected: an object that does work but returns no data when reading from it.
Actual: a debug assertion error while calling fgetc in FileStream::Read.

Please provide any additional information below.

feof and ferror both report that the FILE* is just fine, but fgetc crashes

Original issue reported on code.google.com by Marcus.I...@gmail.com on 12 Jun 2013 at 1:39

GoogleCodeExporter commented 8 years ago
Update: the file is not actually empty. It has an UTF8 BOM (3 bytes). The fopen 
flags are "r, ccs=UTF-8".

Original comment by Marcus.I...@gmail.com on 12 Jun 2013 at 1:44

GoogleCodeExporter commented 8 years ago
Update 2: it works when opening the files with "rb" and "wb" respectively.

Original comment by Marcus.I...@gmail.com on 12 Jun 2013 at 2:01

GoogleCodeExporter commented 8 years ago
On what platform does it happen?

Original comment by milo...@gmail.com on 18 Jun 2013 at 1:39

GoogleCodeExporter commented 8 years ago
It's Windows 8, x64, MSVC 2012

Original comment by Marcus.I...@gmail.com on 18 Jun 2013 at 10:06

GoogleCodeExporter commented 8 years ago
I suggest using "rb" and "wb" on Windows. So that Windows does not do any 
conversions as using "r" and "w" in most other systems.
"ccs" are not cross-platform. Current version of RapidJSON can handle encoding 
conversions internally. I would suggest using this function.
Please refer to:
http://miloyip.github.io/rapidjson/md_doc_stream.html#EncodedStreams

Original comment by milo...@gmail.com on 13 Jul 2014 at 5:03