You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tcl.apache.org by mx...@apache.org on 2018/12/17 00:11:25 UTC
[tcl-rivet] branch winbuild updated: several changes to resolve
ambiguities in implicit casting int from and to size_t
This is an automated email from the ASF dual-hosted git repository.
mxmanghi pushed a commit to branch winbuild
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git
The following commit(s) were added to refs/heads/winbuild by this push:
new 53de5f8 several changes to resolve ambiguities in implicit casting int from and to size_t
53de5f8 is described below
commit 53de5f8905414452136b7bb0b7c470e51e82ecd0
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Mon Dec 17 01:11:13 2018 +0100
several changes to resolve ambiguities in implicit casting int from and to size_t
---
ChangeLog | 7 ++++
src/librivet/rivetList.c | 4 +-
src/mod_rivet_ng/TclWebapache.c | 4 +-
src/mod_rivet_ng/rivetCore.c | 5 +--
src/mod_rivet_ng/rivet_types.h | 2 +-
src/request/apache_multipart_buffer.c | 73 ++++++++++++++++++-----------------
src/request/apache_multipart_buffer.h | 28 +++++++-------
src/request/apache_request.c | 46 ++++++++++++----------
8 files changed, 91 insertions(+), 78 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5c05583..829430f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-12-17 Massimo Manghi <mx...@apache.org>
+ * src/request/apache_request.c,src/request/apache_multipart_buffer.[c|h]:
+ explicit cast to int wherever needed by calls to Tcl_* functions and changed
+ int to size_t wherever required
+ * src/mod_rivet_ng/rivet_types.h,rivetCore.c: field 'size' in structure typed as size_t
+ * src/mod_rivet_ng/TclWebapache.c: argument to Tcl_ReadChars explicitly cast to int
+
2018-12-16 Georgios Petasis <pe...@apache.org>
* Readme.md: Added a Markdown README file, which shows the build status
from Appveyor, for Windows.
diff --git a/src/librivet/rivetList.c b/src/librivet/rivetList.c
index 4847acf..5884756 100644
--- a/src/librivet/rivetList.c
+++ b/src/librivet/rivetList.c
@@ -464,10 +464,10 @@ Rivet_CommaJoinObjCmd (notUsed, interp, objc, objv)
* calculations right!
*/
- Tcl_AppendToObj (resultPtr, strPtr, walkPtr - strPtr);
+ Tcl_AppendToObj (resultPtr, strPtr, (int)(walkPtr - strPtr));
strPtr = walkPtr - 1;
}
- Tcl_AppendToObj (resultPtr, strPtr, walkPtr - strPtr);
+ Tcl_AppendToObj (resultPtr, strPtr, (int)(walkPtr - strPtr));
}
Tcl_AppendToObj (resultPtr, "\"", 1);
return TCL_OK;
diff --git a/src/mod_rivet_ng/TclWebapache.c b/src/mod_rivet_ng/TclWebapache.c
index 4bf8a6b..2446072 100644
--- a/src/mod_rivet_ng/TclWebapache.c
+++ b/src/mod_rivet_ng/TclWebapache.c
@@ -725,7 +725,7 @@ int TclWeb_UploadData(char *varname, Tcl_Obj *data, TclWebRequest *req)
}
/* Put data in a variable */
- Tcl_ReadChars(chan, data, ApacheUpload_size(req->upload), 0);
+ Tcl_ReadChars(chan, data, (int)ApacheUpload_size(req->upload), 0);
if (Tcl_Close(req->interp, chan) == TCL_ERROR) {
return TCL_ERROR;
}
@@ -739,7 +739,7 @@ int TclWeb_UploadData(char *varname, Tcl_Obj *data, TclWebRequest *req)
int TclWeb_UploadSize(Tcl_Obj *sz, TclWebRequest *req)
{
- Tcl_SetIntObj(sz, ApacheUpload_size(req->upload));
+ Tcl_SetIntObj(sz, (int)ApacheUpload_size(req->upload));
return TCL_OK;
}
diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index 66cb9d8..2c871e9 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -151,7 +151,7 @@ TCL_CMD_HEADER( Rivet_MakeURL )
{
/* relative path */
char* script_name = TclWeb_GetEnvVar (private,"SCRIPT_NAME");
- int script_name_l = strlen(script_name);
+ size_t script_name_l = strlen(script_name);
// regardless the reason for a SCRIPT_NAME being undefined we
// prevent a segfault and we revert the behavior of makeurl
@@ -1791,8 +1791,7 @@ TCL_CMD_HEADER( Rivet_LogErrorCmd )
return TCL_OK;
}
-#define TESTPANIC 0
-
+#undef TESTPANIC
#ifdef TESTPANIC
/*
*----------------------------------------------------------------------
diff --git a/src/mod_rivet_ng/rivet_types.h b/src/mod_rivet_ng/rivet_types.h
index 25151c5..b8cda08 100644
--- a/src/mod_rivet_ng/rivet_types.h
+++ b/src/mod_rivet_ng/rivet_types.h
@@ -39,7 +39,7 @@ typedef struct _ApacheUpload {
char* tempname;
apr_table_t* info;
apr_file_t* fp;
- long size;
+ size_t size;
ApacheRequest* req;
} ApacheUpload;
diff --git a/src/request/apache_multipart_buffer.c b/src/request/apache_multipart_buffer.c
index 36be086..484b8f3 100644
--- a/src/request/apache_multipart_buffer.c
+++ b/src/request/apache_multipart_buffer.c
@@ -31,25 +31,25 @@
if partial is true, partial matches are allowed at the end of the buffer.
returns NULL if not found, or a pointer to the start of the first match.
*/
-void* my_memstr(char* haystack, int haystacklen, const char* needle,
- int partial)
+void* my_memstr(char* haystack,int haystacklen,const char* needle,int partial)
{
- int needlen = strlen(needle);
+ size_t needlen = strlen(needle);
int len = haystacklen;
char *ptr = haystack;
/* iterate through first character matches */
while( (ptr = memchr(ptr, needle[0], len)) ) {
- /* calculate length after match */
- len = haystacklen - (ptr - (char *)haystack);
-
- /* done if matches up to capacity of buffer */
- if(memcmp(needle, ptr, needlen) == 0 &&
- (partial || len >= needlen))
- break;
-
- /* next character */
- ptr++; len--;
+ /* calculate length after match */
+ len = haystacklen - (int)(ptr - (char *)haystack);
+
+ /* done if matches up to capacity of buffer */
+ if(memcmp(needle, ptr, needlen) == 0 && (partial || len >= needlen))
+ {
+ break;
+ }
+
+ /* next character */
+ ptr++; len--;
}
return ptr;
@@ -73,7 +73,7 @@ int fill_buffer(multipart_buffer *self)
bytes_to_read = self->bufsize - self->bytes_in_buffer;
if (bytes_to_read >= self->r->remaining) {
- bytes_to_read = self->r->remaining - strlen(self->boundary);
+ bytes_to_read = (int)(self->r->remaining - (apr_off_t)strlen(self->boundary));
#ifdef DEBUG
ap_log_rerror(MPB_ERROR, "mozilla 0.97 hack: '%ld'", self->r->remaining);
#endif
@@ -118,7 +118,7 @@ char* next_line(multipart_buffer *self)
/* bump the pointer */
self->buf_begin = ptr + 1;
- self->bytes_in_buffer -= (self->buf_begin - line);
+ self->bytes_in_buffer -= (int)(self->buf_begin - line);
}
/* no LF found */
@@ -177,17 +177,18 @@ int find_boundary(multipart_buffer *self, char *boundary)
/*********************** external functions *********************/
/* create new multipart_buffer structure */
-multipart_buffer *multipart_buffer_new(char *boundary, long length, request_rec *r)
+multipart_buffer *multipart_buffer_new(char *boundary, apr_off_t length, request_rec *r)
{
multipart_buffer *self = (multipart_buffer *)
apr_pcalloc (r->pool, sizeof(multipart_buffer));
- int minsize = strlen(boundary)+6;
+ size_t minsize = strlen(boundary)+6;
+
if(minsize < FILLUNIT) minsize = FILLUNIT;
self->r = r;
self->buffer = (char *) apr_pcalloc(r->pool, minsize+1);
- self->bufsize = minsize;
+ self->bufsize = (int)minsize;
self->request_length = length;
self->boundary = (char*) apr_pstrcat(r->pool, "--", boundary, NULL);
self->boundary_next = (char*) apr_pstrcat(r->pool, "\n", self->boundary, NULL);
@@ -243,35 +244,35 @@ apr_table_t *multipart_buffer_headers(multipart_buffer *self)
}
/* read until a boundary condition */
-int multipart_buffer_read(multipart_buffer *self, char *buf, int bytes)
+size_t multipart_buffer_read(multipart_buffer *self, char *buf, size_t bytes)
{
- int len, max;
- char *bound;
+ size_t max;
+ size_t len;
+ char* bound;
/* fill buffer if needed */
if(bytes > self->bytes_in_buffer) fill_buffer(self);
/* look for a potential boundary match, only read data up to that point */
- if( (bound = my_memstr(self->buf_begin, self->bytes_in_buffer,
- self->boundary_next, 1)) ) {
- max = bound - self->buf_begin;
- } else {
- max = self->bytes_in_buffer;
- }
+ if( (bound = my_memstr(self->buf_begin, self->bytes_in_buffer, self->boundary_next, 1)) ) {
+ max = bound - self->buf_begin;
+ } else {
+ max = self->bytes_in_buffer;
+ }
/* maximum number of bytes we are reading */
len = max < bytes-1 ? max : bytes-1;
/* if we read any data... */
- if(len > 0) {
- /* copy the data */
- memcpy(buf, self->buf_begin, len);
- buf[len] = 0;
- if(bound && len > 0 && buf[len-1] == '\r') buf[--len] = 0;
-
- /* update the buffer */
- self->bytes_in_buffer -= len;
- self->buf_begin += len;
+ if (len > 0) {
+ /* copy the data */
+ memcpy(buf, self->buf_begin, len);
+ buf[len] = 0;
+ if(bound && len > 0 && buf[len-1] == '\r') buf[--len] = 0;
+
+ /* update the buffer */
+ self->bytes_in_buffer -= (int)len;
+ self->buf_begin += len;
}
#ifdef DEBUG
diff --git a/src/request/apache_multipart_buffer.h b/src/request/apache_multipart_buffer.h
index 2237942..b899a46 100644
--- a/src/request/apache_multipart_buffer.h
+++ b/src/request/apache_multipart_buffer.h
@@ -30,27 +30,27 @@
typedef struct _multipart_buffer {
/* request info */
- request_rec *r;
- long request_length;
+ request_rec* r;
+ apr_off_t request_length;
/* read buffer */
- char *buffer;
- char *buf_begin;
- int bufsize;
- int bytes_in_buffer;
+ char* buffer;
+ char* buf_begin;
+ int bufsize;
+ int bytes_in_buffer;
/* boundary info */
- char *boundary;
- char *boundary_next;
- char *boundary_end;
+ char* boundary;
+ char* boundary_next;
+ char* boundary_end;
} multipart_buffer;
-multipart_buffer *multipart_buffer_new(char *boundary, long length, request_rec *r);
+multipart_buffer* multipart_buffer_new(char* boundary,apr_off_t length,request_rec* r);
///*table*/apr_table_t *multipart_buffer_headers(multipart_buffer *self);
-int multipart_buffer_read(multipart_buffer *self, char *buf, int bytes);
-char *multipart_buffer_read_body(multipart_buffer *self);
-apr_table_t *multipart_buffer_headers(multipart_buffer *self);
-int multipart_buffer_eof(multipart_buffer *self);
+size_t multipart_buffer_read(multipart_buffer* self,char* buf,size_t bytes);
+char* multipart_buffer_read_body(multipart_buffer *self);
+apr_table_t* multipart_buffer_headers(multipart_buffer *self);
+int multipart_buffer_eof(multipart_buffer *self);
#ifdef __cplusplus
}
diff --git a/src/request/apache_request.c b/src/request/apache_request.c
index b5f36f9..b370273 100644
--- a/src/request/apache_request.c
+++ b/src/request/apache_request.c
@@ -42,9 +42,12 @@ util_read(ApacheRequest *req, const char **rbuf)
if (ap_should_client_block(r)) {
char buff[HUGE_STRING_LEN];
- int rsize, len_read, rpos=0;
- long length = r->remaining;
+ int len_read;
+ apr_off_t rpos;
+ apr_off_t rsize;
+ apr_off_t length = r->remaining;
+ rpos = 0;
if (length > req->post_max && req->post_max > 0) {
ap_log_rerror(REQ_ERROR,"entity too large (%d, max=%d)",
(int)length, req->post_max);
@@ -509,14 +512,14 @@ apr_file_t *ApacheRequest_tmpfile(ApacheRequest *req, ApacheUpload *upload)
int
ApacheRequest_parse_multipart(ApacheRequest *req,const char* ct)
{
- request_rec *r = req->r;
- int rc = OK;
- long length;
- char *boundary;
- multipart_buffer *mbuff;
- ApacheUpload *upload = NULL;
- apr_status_t status;
- char error[1024];
+ request_rec* r = req->r;
+ int rc = OK;
+ apr_off_t length;
+ char* boundary;
+ multipart_buffer* mbuff;
+ ApacheUpload* upload = NULL;
+ apr_status_t status;
+ char error[1024];
if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) {
return rc;
@@ -533,7 +536,7 @@ ApacheRequest_parse_multipart(ApacheRequest *req,const char* ct)
}
do {
- int blen;
+ size_t blen;
boundary = ap_getword(r->pool, &ct, '=');
if (boundary == NULL)
return DECLINED;
@@ -550,10 +553,12 @@ ApacheRequest_parse_multipart(ApacheRequest *req,const char* ct)
}
while (!multipart_buffer_eof(mbuff)) {
- apr_table_t *header = (apr_table_t*) multipart_buffer_headers(mbuff);
- const char *cd, *param=NULL, *filename=NULL;
- char buff[FILLUNIT];
- int blen;
+ apr_table_t* header = (apr_table_t*) multipart_buffer_headers(mbuff);
+ const char* cd;
+ const char* param = NULL;
+ const char* filename=NULL;
+ char buff[FILLUNIT];
+ size_t blen;
if (!header) {
#ifdef DEBUG
@@ -625,12 +630,13 @@ ApacheRequest_parse_multipart(ApacheRequest *req,const char* ct)
}
while ((blen = multipart_buffer_read(mbuff, buff, sizeof(buff)))) {
- apr_size_t bytes_to_write = (apr_size_t) blen;
- status = apr_file_write(upload->fp,buff,&bytes_to_write);
- if (status != 0) {
- apr_strerror(status,error,1024);
+ apr_size_t bytes_to_write = (apr_size_t) blen;
+ status = apr_file_write(upload->fp,buff,&bytes_to_write);
+
+ if (status != 0) {
+ apr_strerror(status,error,1024);
return HTTP_INTERNAL_SERVER_ERROR;
- }
+ }
upload->size += blen;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org