Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
5d4803a5
Commit
5d4803a5
authored
Jul 27, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More fixes for
https://github.com/cppformat/cppformat/issues/50
.
parent
4c563de7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
20 deletions
+20
-20
format.cc
format.cc
+5
-5
format.h
format.h
+2
-2
posix.cc
posix.cc
+4
-4
test/util-test.cc
test/util-test.cc
+9
-9
No files found.
format.cc
View file @
5d4803a5
...
...
@@ -304,13 +304,13 @@ fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) {
}
fmt
::
internal
::
UTF16ToUTF8
::
UTF16ToUTF8
(
fmt
::
WStringRef
s
)
{
if
(
int
error_code
=
C
onvert
(
s
))
{
if
(
int
error_code
=
c
onvert
(
s
))
{
throw
WindowsError
(
error_code
,
"cannot convert string from UTF-16 to UTF-8"
);
}
}
int
fmt
::
internal
::
UTF16ToUTF8
::
C
onvert
(
fmt
::
WStringRef
s
)
{
int
fmt
::
internal
::
UTF16ToUTF8
::
c
onvert
(
fmt
::
WStringRef
s
)
{
int
length
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
s
.
c_str
(),
-
1
,
0
,
0
,
0
,
0
);
if
(
length
==
0
)
return
GetLastError
();
...
...
@@ -333,7 +333,7 @@ void fmt::WindowsError::init(
#endif
int
fmt
::
internal
::
StrE
rror
(
int
fmt
::
internal
::
safe_stre
rror
(
int
error_code
,
char
*&
buffer
,
std
::
size_t
buffer_size
)
FMT_NOEXCEPT
(
true
)
{
assert
(
buffer
!=
0
&&
buffer_size
!=
0
);
int
result
=
0
;
...
...
@@ -368,7 +368,7 @@ void fmt::internal::FormatSystemErrorMessage(
char
*
system_message
=
0
;
for
(;;)
{
system_message
=
&
buffer
[
0
];
int
result
=
StrE
rror
(
error_code
,
system_message
,
buffer
.
size
());
int
result
=
safe_stre
rror
(
error_code
,
system_message
,
buffer
.
size
());
if
(
result
==
0
)
break
;
if
(
result
!=
ERANGE
)
{
...
...
@@ -400,7 +400,7 @@ void fmt::internal::FormatWinErrorMessage(
error_code
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
reinterpret_cast
<
LPWSTR
>
(
system_message
.
ptr
()),
0
,
0
))
{
UTF16ToUTF8
utf8_message
;
if
(
!
utf8_message
.
C
onvert
(
system_message
.
c_str
()))
{
if
(
!
utf8_message
.
c
onvert
(
system_message
.
c_str
()))
{
out
<<
message
<<
": "
<<
utf8_message
;
return
;
}
...
...
format.h
View file @
5d4803a5
...
...
@@ -521,7 +521,7 @@ class UTF16ToUTF8 {
// Performs conversion returning a system error code instead of
// throwing exception on error.
int
C
onvert
(
WStringRef
s
);
int
c
onvert
(
WStringRef
s
);
};
#endif
...
...
@@ -534,7 +534,7 @@ class UTF16ToUTF8 {
// ERANGE - buffer is not large enough to store the error message
// other - failure
// Buffer should be at least of size 1.
int
StrE
rror
(
int
error_code
,
int
safe_stre
rror
(
int
error_code
,
char
*&
buffer
,
std
::
size_t
buffer_size
)
FMT_NOEXCEPT
(
true
);
void
FormatSystemErrorMessage
(
...
...
posix.cc
View file @
5d4803a5
...
...
@@ -57,11 +57,11 @@ namespace {
#ifdef _WIN32
// On Windows the count argument to read and write is unsigned, so convert
// it from size_t preventing integer overflow.
inline
unsigned
ConvertRWC
ount
(
std
::
size_t
count
)
{
inline
unsigned
convert_rwc
ount
(
std
::
size_t
count
)
{
return
count
<=
UINT_MAX
?
static_cast
<
unsigned
>
(
count
)
:
UINT_MAX
;
}
#else
inline
std
::
size_t
ConvertRWC
ount
(
std
::
size_t
count
)
{
return
count
;
}
inline
std
::
size_t
convert_rwc
ount
(
std
::
size_t
count
)
{
return
count
;
}
#endif
}
...
...
@@ -118,7 +118,7 @@ void fmt::File::close() {
std
::
streamsize
fmt
::
File
::
read
(
void
*
buffer
,
std
::
size_t
count
)
{
std
::
streamsize
result
=
0
;
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
read
(
fd_
,
buffer
,
ConvertRWC
ount
(
count
))));
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
read
(
fd_
,
buffer
,
convert_rwc
ount
(
count
))));
if
(
result
==
-
1
)
throw
SystemError
(
errno
,
"cannot read from file"
);
return
result
;
...
...
@@ -126,7 +126,7 @@ std::streamsize fmt::File::read(void *buffer, std::size_t count) {
std
::
streamsize
fmt
::
File
::
write
(
const
void
*
buffer
,
std
::
size_t
count
)
{
std
::
streamsize
result
=
0
;
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
write
(
fd_
,
buffer
,
ConvertRWC
ount
(
count
))));
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
write
(
fd_
,
buffer
,
convert_rwc
ount
(
count
))));
if
(
result
==
-
1
)
throw
SystemError
(
errno
,
"cannot write to file"
);
return
result
;
...
...
test/util-test.cc
View file @
5d4803a5
...
...
@@ -410,38 +410,38 @@ TEST(UtilTest, UTF8ToUTF16Error) {
TEST
(
UtilTest
,
UTF16ToUTF8Convert
)
{
fmt
::
internal
::
UTF16ToUTF8
u
;
EXPECT_EQ
(
ERROR_INVALID_PARAMETER
,
u
.
C
onvert
(
0
));
EXPECT_EQ
(
ERROR_INVALID_PARAMETER
,
u
.
c
onvert
(
0
));
}
#endif // _WIN32
TEST
(
UtilTest
,
StrError
)
{
using
fmt
::
internal
::
StrE
rror
;
using
fmt
::
internal
::
safe_stre
rror
;
char
*
message
=
0
;
char
buffer
[
BUFFER_SIZE
];
#ifndef NDEBUG
EXPECT_DEBUG_DEATH
(
StrE
rror
(
EDOM
,
message
=
0
,
0
),
"Assertion"
);
EXPECT_DEBUG_DEATH
(
StrE
rror
(
EDOM
,
message
=
buffer
,
0
),
"Assertion"
);
EXPECT_DEBUG_DEATH
(
safe_stre
rror
(
EDOM
,
message
=
0
,
0
),
"Assertion"
);
EXPECT_DEBUG_DEATH
(
safe_stre
rror
(
EDOM
,
message
=
buffer
,
0
),
"Assertion"
);
#endif
buffer
[
0
]
=
'x'
;
#ifdef _GNU_SOURCE
// Use invalid error code to make sure that
StrE
rror returns an error
// Use invalid error code to make sure that
safe_stre
rror returns an error
// message in the buffer rather than a pointer to a static string.
int
error_code
=
-
1
;
#else
int
error_code
=
EDOM
;
#endif
int
result
=
StrE
rror
(
error_code
,
message
=
buffer
,
BUFFER_SIZE
);
int
result
=
safe_stre
rror
(
error_code
,
message
=
buffer
,
BUFFER_SIZE
);
EXPECT_EQ
(
0
,
result
);
std
::
size_t
message_size
=
std
::
strlen
(
message
);
EXPECT_GE
(
BUFFER_SIZE
-
1u
,
message_size
);
EXPECT_EQ
(
GetSystemErrorMessage
(
error_code
),
message
);
//
StrE
rror never uses buffer on MinGW.
//
safe_stre
rror never uses buffer on MinGW.
#ifndef __MINGW32__
result
=
StrE
rror
(
error_code
,
message
=
buffer
,
message_size
);
result
=
safe_stre
rror
(
error_code
,
message
=
buffer
,
message_size
);
EXPECT_EQ
(
ERANGE
,
result
);
result
=
StrE
rror
(
error_code
,
message
=
buffer
,
1
);
result
=
safe_stre
rror
(
error_code
,
message
=
buffer
,
1
);
EXPECT_EQ
(
buffer
,
message
);
// Message should point to buffer.
EXPECT_EQ
(
ERANGE
,
result
);
EXPECT_STREQ
(
""
,
message
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment