Author: brane
Date: Sat Jul 5 15:46:06 2025
New Revision: 1926976
URL: http://svn.apache.org/viewvc?rev=1926976&view=rev
Log:
Fix some more integer narrowing warnings.
* buckets/deflate_buckets.c
(serf_deflate_refill): Narrow our apr_size_t to Zlib stream's uInt, then
use the already-converted value to compute the crc32.
In two other places, change the type of the private_len variable, which
was unnecessarily declared as an apr_size_t.
* test/CuTest.c
(CuStrCopy, CuStringAppend, CuStringInsert): Cast strlen(...) to int.
* test/test_serf.h
(struct test_baton_t): Add an apr_status_t user baton.
(test/test_context.c): Use the new user status baton for APR status codes.
* test/mock_buckets.c
(next_action): Cast strlen(...) to the expected int.
(test_basic_mock_bucket): Use CuAsertUIntEquals to avoid narrowing.
Modified:
serf/trunk/buckets/deflate_buckets.c
serf/trunk/test/CuTest.c
serf/trunk/test/mock_buckets.c
serf/trunk/test/test_context.c
serf/trunk/test/test_serf.h
Modified: serf/trunk/buckets/deflate_buckets.c
URL:
http://svn.apache.org/viewvc/serf/trunk/buckets/deflate_buckets.c?rev=1926976&r1=1926975&r2=1926976&view=diff
==============================================================================
--- serf/trunk/buckets/deflate_buckets.c (original)
+++ serf/trunk/buckets/deflate_buckets.c Sat Jul 5 15:46:06 2025
@@ -264,11 +264,12 @@ static apr_status_t serf_deflate_refill(
/* Make valgrind happy and explicitly initialize next_in to specific
* value for empty buffer. */
if (private_len) {
- ctx->zstream.next_in = (unsigned char*)private_data;
- ctx->zstream.avail_in = private_len;
+ ctx->zstream.next_in = (Bytef *)private_data;
+ SERF__POSITIVE_TO_INT(ctx->zstream.avail_in, apr_size_t,
private_len);
if (ctx->memLevel >= 0)
- ctx->crc = crc32(ctx->crc, (const Bytef *)private_data,
- private_len);
+ ctx->crc = crc32(ctx->crc,
+ ctx->zstream.next_in,
+ ctx->zstream.avail_in);
} else {
ctx->zstream.next_in = Z_NULL;
ctx->zstream.avail_in = 0;
@@ -295,7 +296,7 @@ static apr_status_t serf_deflate_refill(
if (zRC == Z_BUF_ERROR || ctx->zstream.avail_out == 0) {
/* We're full or zlib requires more space. Either case, clear
out our buffer, reset, and return. */
- apr_size_t private_len;
+ uInt private_len;
serf_bucket_t *tmp;
ctx->zstream.next_out = ctx->buffer;
@@ -317,7 +318,7 @@ static apr_status_t serf_deflate_refill(
}
if (zRC == Z_STREAM_END) {
- apr_size_t private_len;
+ uInt private_len;
serf_bucket_t *tmp;
private_len = ctx->bufferSize - ctx->zstream.avail_out;
Modified: serf/trunk/test/CuTest.c
URL:
http://svn.apache.org/viewvc/serf/trunk/test/CuTest.c?rev=1926976&r1=1926975&r2=1926976&view=diff
==============================================================================
--- serf/trunk/test/CuTest.c (original)
+++ serf/trunk/test/CuTest.c Sat Jul 5 15:46:06 2025
@@ -46,8 +46,7 @@ char* CuStrAlloc(int size)
char* CuStrCopy(const char* old)
{
- int len = strlen(old);
- char* newStr = CuStrAlloc(len + 1);
+ char* newStr = CuStrAlloc(1 + (int)strlen(old));
strcpy(newStr, old);
return newStr;
}
@@ -94,7 +93,7 @@ void CuStringAppend(CuString* str, const
text = "NULL";
}
- length = strlen(text);
+ length = (int)strlen(text);
if (str->length + length + 1 >= str->size)
CuStringResize(str, str->length + length + 1 + STRING_INC);
str->length += length;
@@ -121,7 +120,7 @@ void CuStringAppendFormat(CuString* str,
void CuStringInsert(CuString* str, const char* text, int pos)
{
- int length = strlen(text);
+ int length = (int)strlen(text);
if (pos > str->length)
pos = str->length;
if (str->length + length + 1 >= str->size)
Modified: serf/trunk/test/mock_buckets.c
URL:
http://svn.apache.org/viewvc/serf/trunk/test/mock_buckets.c?rev=1926976&r1=1926975&r2=1926976&view=diff
==============================================================================
--- serf/trunk/test/mock_buckets.c (original)
+++ serf/trunk/test/mock_buckets.c Sat Jul 5 15:46:06 2025
@@ -73,7 +73,7 @@ static apr_status_t next_action(mockbkt_
if (ctx->remaining_data <= 0) {
ctx->current_data = action->data;
ctx->remaining_times = action->times;
- ctx->remaining_data = strlen(action->data);
+ ctx->remaining_data = (int)strlen(action->data);
}
return APR_SUCCESS;
@@ -331,7 +331,7 @@ static void test_basic_mock_bucket(CuTes
for (i = 0; i < 5; i++) {
status = serf_bucket_peek(mock_bkt, &data, &len);
CuAssertIntEquals(tc, APR_SUCCESS, status);
- CuAssertIntEquals(tc, 0, len);
+ CuAssertUIntEquals(tc, 0, len);
CuAssertIntEquals(tc, '\0', *data);
}
@@ -339,7 +339,7 @@ static void test_basic_mock_bucket(CuTes
status = serf_bucket_peek(mock_bkt, &data, &len);
CuAssertIntEquals(tc, APR_EOF, status);
- CuAssertIntEquals(tc, 6, len);
+ CuAssertUIntEquals(tc, 6, len);
CuAssert(tc, "Read data is not equal to expected.",
strncmp("blabla", data, len) == 0);
serf_bucket_destroy(mock_bkt);
Modified: serf/trunk/test/test_context.c
URL:
http://svn.apache.org/viewvc/serf/trunk/test/test_context.c?rev=1926976&r1=1926975&r2=1926976&view=diff
==============================================================================
--- serf/trunk/test/test_context.c (original)
+++ serf/trunk/test/test_context.c Sat Jul 5 15:46:06 2025
@@ -183,7 +183,7 @@ static apr_status_t http_conn_setup_mock
skt,
tb->bkt_alloc);
*input_bkt = serf_bucket_mock_sock_create(skt_bkt,
- tb->user_baton_l,
+ tb->user_baton_s,
tb->bkt_alloc);
return APR_SUCCESS;
@@ -286,7 +286,7 @@ static void test_aborted_connection(CuTe
/* Set up a test context with a server. Use the mock socket to return
APR_ECONNABORTED instead of APR_EOF. */
setup_test_mock_server(tb);
- tb->user_baton_l = APR_ECONNABORTED;
+ tb->user_baton_s = APR_ECONNABORTED;
status = setup_test_client_context(tb, http_conn_setup_mock_socket,
tb->pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
@@ -304,7 +304,7 @@ static void test_aborted_connection_with
/* Set up a test context with a server. Use the mock socket to return
APR_ECONNABORTED instead of APR_EOF. */
setup_test_mock_server(tb);
- tb->user_baton_l = APR_ECONNABORTED;
+ tb->user_baton_s = APR_ECONNABORTED;
status = setup_test_client_context(tb, http_conn_setup_mock_socket,
tb->pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
@@ -323,7 +323,7 @@ static void test_reset_connection(CuTest
/* Set up a test context with a server. Use the mock socket to return
APR_ECONNRESET instead of APR_EOF. */
setup_test_mock_server(tb);
- tb->user_baton_l = APR_ECONNRESET;
+ tb->user_baton_s = APR_ECONNRESET;
status = setup_test_client_context(tb, http_conn_setup_mock_socket,
tb->pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
@@ -341,7 +341,7 @@ static void test_reset_connection_with_a
/* Set up a test context with a server. Use the mock socket to return
APR_ECONNRESET instead of APR_EOF. */
setup_test_mock_server(tb);
- tb->user_baton_l = APR_ECONNRESET;
+ tb->user_baton_s = APR_ECONNRESET;
status = setup_test_client_context(tb, http_conn_setup_mock_socket,
tb->pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
Modified: serf/trunk/test/test_serf.h
URL:
http://svn.apache.org/viewvc/serf/trunk/test/test_serf.h?rev=1926976&r1=1926975&r2=1926976&view=diff
==============================================================================
--- serf/trunk/test/test_serf.h (original)
+++ serf/trunk/test/test_serf.h Sat Jul 5 15:46:06 2025
@@ -90,6 +90,7 @@ typedef struct test_baton_t {
/* Extra batons which can be freely used by tests. */
void *user_baton;
long user_baton_l;
+ apr_status_t user_baton_s;
/* Flags that can be used to report situations, e.g. that a callback was
called. */
@@ -295,7 +296,7 @@ run_client_and_mock_servers_loops_expect
handler_baton_t handler_ctx[],
apr_pool_t *pool);
-/* Logs a test suite error with its code location, and return status
+/* Logs a test suite error with its code location, and return status
SERF_ERROR_ISSUE_IN_TESTSUITE. */
#define REPORT_TEST_SUITE_ERROR()\
test__report_suite_error(__FILE__, __LINE__)