Opened 8 years ago
Closed 7 years ago
#10388 closed Bugs (fixed)
null character at end of string from filesystem::temp_directory_path
Reported by: | anonymous | Owned by: | Beman Dawes |
---|---|---|---|
Milestone: | To Be Determined | Component: | filesystem |
Version: | Boost 1.57.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The null character at end of string causes very interesting bugs that are hard to debug.
Workaround we learned to use is .c_str():
filesystem::path temp_path = filesystem::temp_directory_path( ec ).c_str();
Cause of bug: GetTempPathW(0, 0) returns the size of buffer enought to contain the path, but is might be bigger than (path length + 1). (It rarely happens, but happens.) However the function filesystem::temp_directory_path expects it to be exactly (path length + 1).
Solution: replace lines
buf.pop_back(); path p(buf.begin(), buf.end());
with
path p(buf.begin());
Change History (3)
comment:1 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 7 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Version: | Boost 1.56.0 → Boost 1.57.0 |
The bug is not fixed as of version 1.57. It has nothing to do with `trailing separator'.
Again: `The null character at end of string causes very interesting bugs ...'.
The tested solution: replace lines
buf.pop_back();
path p(buf.begin(), buf.end());
with
path p(buf.begin());
in file \libs\filesystem\src\operations.cpp
The problem is that string returned by GetTempPathW sometimes contain 2 null characters. That means that 1 null character becomes a part of returned path in buggy code, because the code makes assumption that returned string contains exactly 1 null character.
...
Is explanation ok? Or should I just send a patch?
comment:3 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Oops! The trailing_separator comment applied to a different ticket.
Are you sure you are looking at the current state of filesystem? GetTempPathW is no longer used. Please take a look at the develop branch at https://github.com/boostorg/filesystem, and do submit a patch if you think there is still a problem, and then reopen the ticket again.
Thanks,
--Beman
Fixed. A path member function remove_trailing_separator() was added publicly since this may be useful to users.
Thanks,
--Beman