Fix size_t printf formatting

The printf formatting for size_t is set in c99 as %zu but in windows
it is %Iu this is solved by adding and inttypes style PRI macro for size_t

This also uses this macro everywhere size_t is formatted.
This commit is contained in:
Vincent Sanders 2016-03-17 21:55:12 +00:00
parent 232cda5317
commit d15ab96a51
12 changed files with 88 additions and 54 deletions

View File

@ -263,7 +263,8 @@ static void fetch_data_poll(lwc_string *scheme)
char header[64];
fetch_set_http_code(c->parent_fetch, 200);
LOG("setting data: MIME type to %s, length to %zd", c->mimetype, c->datalen);
LOG("setting data: MIME type to %s, length to %" PRIsizet,
c->mimetype, c->datalen);
/* Any callback can result in the fetch being aborted.
* Therefore, we _must_ check for this after _every_
* call to fetch_data_send_callback().
@ -277,8 +278,8 @@ static void fetch_data_poll(lwc_string *scheme)
if (c->aborted == false) {
snprintf(header, sizeof header,
"Content-Length: %"SSIZET_FMT,
c->datalen);
"Content-Length: %" PRIsizet,
c->datalen);
msg.type = FETCH_HEADER;
msg.data.header_or_data.buf =
(const uint8_t *) header;

View File

@ -313,18 +313,21 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx,
/* content type */
if (fetch_file_send_header(ctx, "Content-Type: %s",
guit->fetch->filetype(ctx->path)))
guit->fetch->filetype(ctx->path))) {
goto fetch_file_process_aborted;
}
/* content length */
if (fetch_file_send_header(ctx, "Content-Length: %"SSIZET_FMT, fdstat->st_size))
if (fetch_file_send_header(ctx, "Content-Length: %" PRIsizet,
fdstat->st_size)) {
goto fetch_file_process_aborted;
}
/* create etag */
if (fetch_file_send_header(ctx, "ETag: \"%10" PRId64 "\"",
(int64_t) fdstat->st_mtime))
(int64_t) fdstat->st_mtime)) {
goto fetch_file_process_aborted;
}
msg.type = FETCH_DATA;
msg.data.header_or_data.buf = (const uint8_t *) buf;
@ -393,17 +396,21 @@ fetch_file_process_aborted:
/* content type */
if (fetch_file_send_header(ctx, "Content-Type: %s",
guit->fetch->filetype(ctx->path)))
guit->fetch->filetype(ctx->path))) {
goto fetch_file_process_aborted;
}
/* content length */
if (fetch_file_send_header(ctx, "Content-Length: %"SSIZET_FMT, fdstat->st_size))
if (fetch_file_send_header(ctx, "Content-Length: %" PRIsizet,
fdstat->st_size)) {
goto fetch_file_process_aborted;
}
/* create etag */
if (fetch_file_send_header(ctx, "ETag: \"%10" PRId64 "\"",
(int64_t) fdstat->st_mtime))
(int64_t) fdstat->st_mtime)) {
goto fetch_file_process_aborted;
}
/* main data loop */
while (tot_read < fdstat->st_size) {

View File

@ -16,7 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* resource: URL handling. Based on the data fetcher by Rob Kendrick */
/**
* \file
* resource scheme URL handling. Based on the data fetcher by Rob Kendrick
*/
#include <sys/types.h>
#include <sys/stat.h>
@ -187,20 +190,21 @@ static bool fetch_resource_data_handler(struct fetch_resource_context *ctx)
/* content type */
if (fetch_resource_send_header(ctx, "Content-Type: %s",
guit->fetch->filetype(lwc_string_data(ctx->entry->path))))
guit->fetch->filetype(lwc_string_data(ctx->entry->path)))) {
goto fetch_resource_data_aborted;
}
/* content length */
if (fetch_resource_send_header(ctx,
"Content-Length: %"SSIZET_FMT,
ctx->entry->data_len))
if (fetch_resource_send_header(ctx, "Content-Length: %" PRIsizet,
ctx->entry->data_len)) {
goto fetch_resource_data_aborted;
}
/* create etag */
if (fetch_resource_send_header(ctx,
"ETag: \"%10" PRId64 "\"",
(int64_t) DIRECT_ETAG_VALUE))
if (fetch_resource_send_header(ctx, "ETag: \"%10" PRId64 "\"",
(int64_t) DIRECT_ETAG_VALUE)) {
goto fetch_resource_data_aborted;
}
msg.type = FETCH_DATA;

View File

@ -1239,7 +1239,7 @@ llcache_serialise_metadata(llcache_object *object,
datasize -= use;
/* object size */
use = snprintf(op, datasize, "%zu", object->source_len);
use = snprintf(op, datasize, "%" PRIsizet, object->source_len);
if (use < 0) {
goto operror;
}
@ -1274,7 +1274,7 @@ llcache_serialise_metadata(llcache_object *object,
datasize -= use;
/* number of headers */
use = snprintf(op, datasize, "%zu", object->num_headers);
use = snprintf(op, datasize, "%" PRIsizet, object->num_headers);
if (use < 0) {
goto operror;
}
@ -1386,7 +1386,8 @@ llcache_process_metadata(llcache_object *object)
* by simply skipping caching of this object.
*/
LOG("Got metadata for %s instead of %s", nsurl_access(metadataurl), nsurl_access(object->url));
LOG("Got metadata for %s instead of %s",
nsurl_access(metadataurl), nsurl_access(object->url));
nsurl_unref(metadataurl);
@ -1402,7 +1403,7 @@ llcache_process_metadata(llcache_object *object)
ln += lnsize + 1;
lnsize = strlen(ln);
if ((lnsize < 1) || (sscanf(ln, "%zu", &source_length) != 1)) {
if ((lnsize < 1) || (sscanf(ln, "%" PRIsizet, &source_length) != 1)) {
res = NSERROR_INVALID;
goto format_error;
}
@ -1443,7 +1444,7 @@ llcache_process_metadata(llcache_object *object)
ln += lnsize + 1;
lnsize = strlen(ln);
if ((lnsize < 1) || (sscanf(ln, "%zu", &num_headers) != 1)) {
if ((lnsize < 1) || (sscanf(ln, "%" PRIsizet, &num_headers) != 1)) {
res = NSERROR_INVALID;
goto format_error;
}
@ -2461,7 +2462,7 @@ static void llcache_persist_slowcheck(void *p)
total_bandwidth = (llcache->total_written * 1000) / llcache->total_elapsed;
if (total_bandwidth < llcache->minimum_bandwidth) {
LOG("Current bandwidth %"PRIu64" less than minimum %zd",
LOG("Current bandwidth %" PRIu64 " less than minimum %" PRIsizet,
total_bandwidth, llcache->minimum_bandwidth);
guit->llcache->finalise();
}

View File

@ -161,7 +161,8 @@ nserror netsurf_init(const char *store_path)
if (hlcache_parameters.llcache.limit < MINIMUM_MEMORY_CACHE_SIZE) {
hlcache_parameters.llcache.limit = MINIMUM_MEMORY_CACHE_SIZE;
LOG("Setting minimum memory cache size %zd", hlcache_parameters.llcache.limit);
LOG("Setting minimum memory cache size %" PRIsizet,
hlcache_parameters.llcache.limit);
}
/* Set up the max attempts made to fetch a timing out resource */

View File

@ -374,7 +374,7 @@ image_cache_init(const struct image_cache_parameters *image_cache_parameters)
image_cache__background_update,
image_cache);
LOG("Image cache initilised with a limit of %zd hysteresis of %zd",
LOG("Image cache initilised with a limit of %" PRIsizet " hysteresis of %"PRIsizet,
image_cache->params.limit, image_cache->params.hysteresis);
return NSERROR_OK;
@ -387,7 +387,7 @@ nserror image_cache_fini(void)
guit->browser->schedule(-1, image_cache__background_update, image_cache);
LOG("Size at finish %zd (in %d)",
LOG("Size at finish %" PRIsizet " (in %d)",
image_cache->total_bitmap_size, image_cache->bitmap_count);
while (image_cache->entries != NULL) {
@ -399,9 +399,9 @@ nserror image_cache_fini(void)
image_cache->fail_count;
LOG("Age %ds", image_cache->current_age / 1000);
LOG("Peak size %zd (in %d)",
LOG("Peak size %" PRIsizet " (in %d)",
image_cache->max_bitmap_size, image_cache->max_bitmap_size_count);
LOG("Peak image count %d (size %zd)",
LOG("Peak image count %d (size %" PRIsizet ")",
image_cache->max_bitmap_count, image_cache->max_bitmap_count_size);
if (op_count > 0) {
@ -570,15 +570,15 @@ case chr : \
slen++;
break;
FMTCHR('a', SSIZET_FMT, params.limit);
FMTCHR('b', SSIZET_FMT, params.hysteresis);
FMTCHR('c', SSIZET_FMT, total_bitmap_size);
FMTCHR('a', PRIssizet, params.limit);
FMTCHR('b', PRIssizet, params.hysteresis);
FMTCHR('c', PRIssizet, total_bitmap_size);
FMTCHR('d', "d", bitmap_count);
FMTCHR('e', "d", current_age / 1000);
FMTCHR('f', SSIZET_FMT, max_bitmap_size);
FMTCHR('f', PRIssizet, max_bitmap_size);
FMTCHR('g', "d", max_bitmap_size_count);
FMTCHR('h', "d", max_bitmap_count);
FMTCHR('i', SSIZET_FMT, max_bitmap_count_size);
FMTCHR('i', PRIssizet, max_bitmap_count_size);
case 'j':
@ -705,7 +705,7 @@ int image_cache_snentryf(char *string, size_t size, unsigned int entryn,
if (centry->bitmap != NULL) {
slen += snprintf(string + slen,
size - slen,
"%"SSIZET_FMT,
"%" PRIssizet,
centry->bitmap_size);
} else {
slen += snprintf(string + slen,

View File

@ -172,7 +172,10 @@ static void info_callback(png_structp png_s, png_infop info)
png_c->rowbytes = png_get_rowbytes(png_s, info);
png_c->interlace = (interlace == PNG_INTERLACE_ADAM7);
LOG("size %li * %li, rowbytes %zu", (unsigned long)width, (unsigned long)height, png_c->rowbytes);
LOG("size %li * %li, rowbytes %" PRIsizet,
(unsigned long)width,
(unsigned long)height,
png_c->rowbytes);
}
static void row_callback(png_structp png_s, png_bytep new_row,

View File

@ -215,7 +215,7 @@ static void html_css_fetcher_poll(lwc_string *scheme)
if (c->aborted == false) {
snprintf(header, sizeof header,
"Content-Length: %"SSIZET_FMT,
"Content-Length: %"PRIsizet,
dom_string_byte_length(c->item->data));
msg.type = FETCH_HEADER;
msg.data.header_or_data.buf =

View File

@ -453,14 +453,14 @@ static bool idna__is_valid(int32_t *label, size_t len)
/* 4. Check characters not DISALLOWED by RFC5892 */
if (idna_prop == IDNA_P_DISALLOWED) {
LOG("Check failed: character %zd (%x) is DISALLOWED", i, label[i]);
LOG("Check failed: character %" PRIsizet " (%x) is DISALLOWED", i, label[i]);
return false;
}
/* 5. Check CONTEXTJ characters conform to defined rules */
if (idna_prop == IDNA_P_CONTEXTJ) {
if (idna__contextj_rule(label, i, len) == false) {
LOG("Check failed: character %zd (%x) does not conform to CONTEXTJ rule", i, label[i]);
LOG("Check failed: character %" PRIsizet " (%x) does not conform to CONTEXTJ rule", i, label[i]);
return false;
}
}
@ -469,14 +469,14 @@ static bool idna__is_valid(int32_t *label, size_t len)
/** \todo optionally we can check conformance to this rule */
if (idna_prop == IDNA_P_CONTEXTO) {
if (idna__contexto_rule(label[i]) == false) {
LOG("Check failed: character %zd (%x) has no CONTEXTO rule defined", i, label[i]);
LOG("Check failed: character %" PRIsizet " (%x) has no CONTEXTO rule defined", i, label[i]);
return false;
}
}
/* 7. Check characters are not UNASSIGNED */
if (idna_prop == IDNA_P_UNASSIGNED) {
LOG("Check failed: character %zd (%x) is UNASSIGNED", i, label[i]);
LOG("Check failed: character %" PRIsizet " (%x) is UNASSIGNED", i, label[i]);
return false;
}

View File

@ -77,12 +77,22 @@ struct dirent;
#define PRId64 "lld"
#endif
/* Windows does not have POSIX formating codes or mkdir so work around that */
/* Windows does not have sizet formating codes or POSIX mkdir so work
* around that
*/
#if defined(_WIN32)
#define SSIZET_FMT "Iu"
/** windows printf formatting for size_t type */
#define PRIsizet "Iu"
/** windows printf formatting for ssize_t type */
#define PRIssizet "Id"
/** windows mkdir function */
#define nsmkdir(dir, mode) mkdir((dir))
#else
#define SSIZET_FMT "zd"
/** c99 standard printf formatting for size_t type */
#define PRIsizet "zu"
/** c99 standard printf formatting for ssize_t type */
#define PRIssizet "zd"
/** POSIX mkdir function */
#define nsmkdir(dir, mode) mkdir((dir), (mode))
#endif

View File

@ -57,6 +57,7 @@ void *win32_bitmap_create(int width, int height, unsigned int state)
if (pbmi == NULL) {
return NULL;
}
pbmi->bV5Size = sizeof(BITMAPV5HEADER);
pbmi->bV5Width = width;
pbmi->bV5Height = -height;
@ -71,7 +72,6 @@ void *win32_bitmap_create(int width, int height, unsigned int state)
windib = CreateDIBSection(NULL, (BITMAPINFO *)pbmi, DIB_RGB_COLORS, (void **)&pixdata, NULL, 0);
if (windib == NULL) {
free(pbmi);
return NULL;
@ -286,11 +286,13 @@ struct bitmap *bitmap_scale(struct bitmap *prescale, int width, int height)
* transfer */
if (ret == NULL)
return NULL;
retpixdata = malloc(width * height * 4);
if (retpixdata == NULL) {
free(ret);
return NULL;
}
inpixdata = (uint32_t *)prescale->pixdata;
ret->pixdata = (uint8_t *)retpixdata;
ret->height = height;
@ -307,8 +309,11 @@ struct bitmap *bitmap_scale(struct bitmap *prescale, int width, int height)
}
struct bitmap *bitmap_pretile(struct bitmap *untiled, int width, int height,
bitmap_flags_t flags)
struct bitmap *
bitmap_pretile(struct bitmap *untiled,
int width,
int height,
bitmap_flags_t flags)
{
struct bitmap *ret = malloc(sizeof(struct bitmap));
if (ret == NULL)
@ -352,7 +357,8 @@ struct bitmap *bitmap_pretile(struct bitmap *untiled, int width, int height,
return ret;
}
static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
static nserror
bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
{
int width;
int height;
@ -368,7 +374,8 @@ static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *conte
height = ((width * bitmap->height) + (bitmap->width / 2)) /
bitmap->width;
LOG("bitmap %p for content %p width %d, height %d", bitmap, content, width, height);
LOG("bitmap %p for content %p width %d, height %d",
bitmap, content, width, height);
/* create two memory device contexts to put the bitmaps in */
bufferdc = CreateCompatibleDC(NULL);

View File

@ -1451,16 +1451,16 @@ win32_window_update_box(struct gui_window *gw, const struct rect *rect)
static void win32_window_get_dimensions(struct gui_window *w, int *width, int *height,
static void win32_window_get_dimensions(struct gui_window *gw, int *width, int *height,
bool scaled)
{
if (w == NULL)
if (gw == NULL)
return;
LOG("get dimensions %p w=%d h=%d", w, w->width, w->height);
LOG("get dimensions %p w=%d h=%d", gw, gw->width, gw->height);
*width = w->width;
*height = w->height;
*width = gw->width;
*height = gw->height;
}
static void win32_window_update_extent(struct gui_window *w)