Skip to content

Commit 8e4da9b

Browse files
authored
Fix two issues (aws#189)
(1) Missing initializer issues for gcc 4.9.4. (2) StdIOStreamInputStream::ReadImpl() should return true when attempting to read bytes from empty stream.
1 parent d975770 commit 8e4da9b

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

include/aws/crt/auth/Credentials.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ namespace Aws
125125
*/
126126
struct AWS_CRT_CPP_API CredentialsProviderStaticConfig
127127
{
128-
CredentialsProviderStaticConfig() : AccessKeyId{}, SecretAccessKey{}, SessionToken{} {}
128+
CredentialsProviderStaticConfig()
129+
{
130+
AWS_ZERO_STRUCT(AccessKeyId);
131+
AWS_ZERO_STRUCT(SecretAccessKey);
132+
AWS_ZERO_STRUCT(SessionToken);
133+
}
129134

130135
/**
131136
* The value of the access key component for the provider's static aws credentials
@@ -149,8 +154,10 @@ namespace Aws
149154
struct AWS_CRT_CPP_API CredentialsProviderProfileConfig
150155
{
151156
CredentialsProviderProfileConfig()
152-
: ProfileNameOverride{}, ConfigFileNameOverride{}, CredentialsFileNameOverride{}
153157
{
158+
AWS_ZERO_STRUCT(ProfileNameOverride);
159+
AWS_ZERO_STRUCT(ConfigFileNameOverride);
160+
AWS_ZERO_STRUCT(CredentialsFileNameOverride);
154161
}
155162

156163
/**

source/io/Stream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace Aws
114114
auto read = m_stream->gcount();
115115
buffer.len += static_cast<size_t>(read);
116116

117-
if (read > 0)
117+
if (read > 0 || (read == 0 && m_stream->eof()))
118118
{
119119
return true;
120120
}

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_test_case(OptionalCopyAndMoveSemantics)
3737
add_test_case(StreamTestCreateDestroyWrapper)
3838
add_test_case(StreamTestLength)
3939
add_test_case(StreamTestRead)
40+
add_test_case(StreamTestReadEmpty)
4041
add_test_case(StreamTestSeekBegin)
4142
add_test_case(StreamTestSeekEnd)
4243
add_test_case(TestCredentialsConstruction)

tests/StreamTest.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int s_StreamTestRead(struct aws_allocator *allocator, void *ctx)
7272
AWS_ZERO_STRUCT(buffer);
7373
aws_byte_buf_init(&buffer, allocator, 256);
7474

75-
aws_input_stream_read(wrappedStream.GetUnderlyingStream(), &buffer);
75+
ASSERT_SUCCESS(aws_input_stream_read(wrappedStream.GetUnderlyingStream(), &buffer));
7676

7777
ASSERT_TRUE(buffer.len == strlen(STREAM_CONTENTS));
7878
ASSERT_BIN_ARRAYS_EQUALS(STREAM_CONTENTS, buffer.len, buffer.buffer, buffer.len);
@@ -87,6 +87,34 @@ static int s_StreamTestRead(struct aws_allocator *allocator, void *ctx)
8787

8888
AWS_TEST_CASE(StreamTestRead, s_StreamTestRead)
8989

90+
static int s_StreamTestReadEmpty(struct aws_allocator *allocator, void *ctx)
91+
{
92+
(void)ctx;
93+
{
94+
Aws::Crt::ApiHandle apiHandle(allocator);
95+
96+
auto stringStream = Aws::Crt::MakeShared<Aws::Crt::StringStream>(allocator, "");
97+
98+
Aws::Crt::Io::StdIOStreamInputStream wrappedStream(stringStream, allocator);
99+
100+
aws_byte_buf buffer;
101+
AWS_ZERO_STRUCT(buffer);
102+
aws_byte_buf_init(&buffer, allocator, 256);
103+
104+
ASSERT_SUCCESS(aws_input_stream_read(wrappedStream.GetUnderlyingStream(), &buffer));
105+
106+
ASSERT_TRUE(buffer.len == 0);
107+
108+
aws_byte_buf_clean_up(&buffer);
109+
}
110+
111+
Aws::Crt::TestCleanupAndWait();
112+
113+
return AWS_OP_SUCCESS;
114+
}
115+
116+
AWS_TEST_CASE(StreamTestReadEmpty, s_StreamTestReadEmpty)
117+
90118
static const aws_off_t BEGIN_SEEK_OFFSET = 4;
91119

92120
static int s_StreamTestSeekBegin(struct aws_allocator *allocator, void *ctx)
@@ -105,7 +133,7 @@ static int s_StreamTestSeekBegin(struct aws_allocator *allocator, void *ctx)
105133
AWS_ZERO_STRUCT(buffer);
106134
aws_byte_buf_init(&buffer, allocator, 256);
107135

108-
aws_input_stream_read(wrappedStream.GetUnderlyingStream(), &buffer);
136+
ASSERT_SUCCESS(aws_input_stream_read(wrappedStream.GetUnderlyingStream(), &buffer));
109137

110138
ASSERT_TRUE(buffer.len == strlen(STREAM_CONTENTS) - BEGIN_SEEK_OFFSET);
111139
ASSERT_BIN_ARRAYS_EQUALS(STREAM_CONTENTS + BEGIN_SEEK_OFFSET, buffer.len, buffer.buffer, buffer.len);
@@ -138,7 +166,7 @@ static int s_StreamTestSeekEnd(struct aws_allocator *allocator, void *ctx)
138166
AWS_ZERO_STRUCT(buffer);
139167
aws_byte_buf_init(&buffer, allocator, 256);
140168

141-
aws_input_stream_read(wrappedStream.GetUnderlyingStream(), &buffer);
169+
ASSERT_SUCCESS(aws_input_stream_read(wrappedStream.GetUnderlyingStream(), &buffer));
142170

143171
ASSERT_TRUE(buffer.len == -END_SEEK_OFFSET);
144172
ASSERT_BIN_ARRAYS_EQUALS(

0 commit comments

Comments
 (0)