Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Willers
KWSys
Commits
4967ccc0
Commit
4967ccc0
authored
8 years ago
by
Dāvis Mosāns
Committed by
Brad King
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ConsoleBuf: Fix output for strings that contain null byte
Change-Id: I941dcebe0193112f0d5aaf77cac55246febe4d3c
parent
f069db91
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ConsoleBuf.hxx.in
+2
-3
2 additions, 3 deletions
ConsoleBuf.hxx.in
testConsoleBuf.cxx
+24
-9
24 additions, 9 deletions
testConsoleBuf.cxx
testConsoleBuf.hxx
+1
-1
1 addition, 1 deletion
testConsoleBuf.hxx
testConsoleBufChild.cxx
+2
-1
2 additions, 1 deletion
testConsoleBufChild.cxx
with
29 additions
and
14 deletions
ConsoleBuf.hxx.in
+
2
−
3
View file @
4967ccc0
...
...
@@ -327,14 +327,13 @@ private:
const int length =
WideCharToMultiByte(m_activeOutputCodepage, 0, wbuffer.c_str(),
(int)wbuffer.size(), NULL, 0, NULL, NULL);
char* buf = new char[length
+ 1
];
char* buf = new char[length];
const bool success =
WideCharToMultiByte(m_activeOutputCodepage, 0, wbuffer.c_str(),
(int)wbuffer.size(), buf, length, NULL, NULL) > 0
? true
: false;
buf[length] = '\0';
buffer = buf;
buffer = std::string(buf, length);
delete[] buf;
return success;
}
...
...
This diff is collapsed.
Click to expand it.
testConsoleBuf.cxx
+
24
−
9
View file @
4967ccc0
...
...
@@ -18,6 +18,7 @@
#if defined(_WIN32)
#include
<algorithm>
#include
<iomanip>
#include
<iostream>
#include
<stdexcept>
...
...
@@ -318,6 +319,7 @@ static int testPipe()
bytesRead
==
0
)
{
throw
std
::
runtime_error
(
"ReadFile#1 failed!"
);
}
buffer
[
bytesRead
]
=
0
;
if
((
bytesRead
<
encodedTestString
.
size
()
+
1
+
encodedInputTestString
.
size
()
&&
!
ReadFile
(
outPipeRead
,
buffer
+
bytesRead
,
...
...
@@ -336,8 +338,12 @@ static int testPipe()
bytesRead
==
0
)
{
throw
std
::
runtime_error
(
"ReadFile#3 failed!"
);
}
buffer2
[
bytesRead
-
1
]
=
0
;
didFail
=
encodedTestString
.
compare
(
buffer2
)
==
0
?
0
:
1
;
buffer2
[
bytesRead
]
=
0
;
didFail
=
encodedTestString
.
compare
(
0
,
encodedTestString
.
npos
,
buffer2
,
encodedTestString
.
size
())
==
0
?
0
:
1
;
}
if
(
didFail
!=
0
)
{
std
::
cerr
<<
"Pipe's output didn't match expected output!"
...
...
@@ -423,23 +429,28 @@ static int testFile()
bytesRead
==
0
)
{
throw
std
::
runtime_error
(
"ReadFile#1 failed!"
);
}
buffer
[
bytesRead
-
1
]
=
0
;
buffer
[
bytesRead
]
=
0
;
if
(
memcmp
(
buffer
,
encodedTestString
.
c_str
(),
encodedTestString
.
size
())
==
0
&&
memcmp
(
buffer
+
encodedTestString
.
size
()
+
1
,
encodedInputTestString
.
c_str
(),
encodedInputTestString
.
size
()
-
1
)
==
0
)
{
encodedInputTestString
.
size
())
==
0
)
{
bytesRead
=
0
;
if
(
SetFilePointer
(
errFile
,
0
,
0
,
FILE_BEGIN
)
==
INVALID_SET_FILE_POINTER
)
{
throw
std
::
runtime_error
(
"SetFilePointer#2 failed!"
);
}
if
(
!
ReadFile
(
errFile
,
buffer2
,
sizeof
(
buffer2
),
&
bytesRead
,
NULL
)
||
bytesRead
==
0
)
{
throw
std
::
runtime_error
(
"ReadFile#2 failed!"
);
}
buffer2
[
bytesRead
-
1
]
=
0
;
didFail
=
encodedTestString
.
compare
(
buffer2
)
==
0
?
0
:
1
;
buffer2
[
bytesRead
]
=
0
;
didFail
=
encodedTestString
.
compare
(
0
,
encodedTestString
.
npos
,
buffer2
,
encodedTestString
.
size
())
==
0
?
0
:
1
;
}
if
(
didFail
!=
0
)
{
std
::
cerr
<<
"File's output didn't match expected output!"
...
...
@@ -448,7 +459,7 @@ static int testFile()
encodedTestString
.
size
());
dumpBuffers
<
char
>
(
encodedInputTestString
.
c_str
(),
buffer
+
encodedTestString
.
size
()
+
1
,
encodedInputTestString
.
size
()
-
1
);
encodedInputTestString
.
size
());
dumpBuffers
<
char
>
(
encodedTestString
.
c_str
(),
buffer2
,
encodedTestString
.
size
());
}
...
...
@@ -685,6 +696,7 @@ static int testConsole()
throw
std
::
runtime_error
(
"ReadConsoleOutputCharacter failed!"
);
}
std
::
wstring
wideTestString
=
kwsys
::
Encoding
::
ToWide
(
encodedTestString
);
std
::
replace
(
wideTestString
.
begin
(),
wideTestString
.
end
(),
'\0'
,
' '
);
std
::
wstring
wideInputTestString
=
kwsys
::
Encoding
::
ToWide
(
encodedInputTestString
);
if
(
memcmp
(
outputBuffer
,
wideTestString
.
c_str
(),
...
...
@@ -757,8 +769,11 @@ int testConsoleBuf(int, char* [])
return
1
;
}
encodedTestString
=
kwsys
::
Encoding
::
ToNarrow
(
UnicodeTestString
);
encodedInputTestString
=
kwsys
::
Encoding
::
ToNarrow
(
UnicodeInputTestString
);
encodedTestString
=
kwsys
::
Encoding
::
ToNarrow
(
std
::
wstring
(
UnicodeTestString
,
sizeof
(
UnicodeTestString
)
/
sizeof
(
wchar_t
)
-
1
));
encodedInputTestString
=
kwsys
::
Encoding
::
ToNarrow
(
std
::
wstring
(
UnicodeInputTestString
,
sizeof
(
UnicodeInputTestString
)
/
sizeof
(
wchar_t
)
-
1
));
encodedInputTestString
+=
"
\n
"
;
ret
|=
testPipe
();
...
...
This diff is collapsed.
Click to expand it.
testConsoleBuf.hxx
+
1
−
1
View file @
4967ccc0
...
...
@@ -11,7 +11,7 @@ static const wchar_t AfterOutputEventName[] = L"AfterOutputEvent";
// यूनिकोड είναι здорово!
static
const
wchar_t
UnicodeTestString
[]
=
L"\u092F\u0942\u0928\u093F\u0915\u094B\u0921 "
L"\u03B5\u03AF\u03BD\u03B1\u03B9 "
L"\u03B5\u03AF\u03BD
\
0
\
u03B1\u03B9 "
L"\u0437\u0434\u043E\u0440\u043E\u0432\u043E!"
;
#endif
This diff is collapsed.
Click to expand it.
testConsoleBufChild.cxx
+
2
−
1
View file @
4967ccc0
...
...
@@ -28,7 +28,8 @@ int main(int argc, const char* argv[])
std
::
cout
<<
argv
[
1
]
<<
std
::
endl
;
std
::
cerr
<<
argv
[
1
]
<<
std
::
endl
;
}
else
{
std
::
string
str
=
kwsys
::
Encoding
::
ToNarrow
(
UnicodeTestString
);
std
::
string
str
=
kwsys
::
Encoding
::
ToNarrow
(
std
::
wstring
(
UnicodeTestString
,
sizeof
(
UnicodeTestString
)
/
sizeof
(
wchar_t
)
-
1
));
std
::
cout
<<
str
<<
std
::
endl
;
std
::
cerr
<<
str
<<
std
::
endl
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment