mirror of
https://github.com/curl/curl.git
synced 2026-07-23 02:17:21 +03:00
examples/complicated: fix warnings, bump deprecated callback, tidy up
Also: make them C89, add consts. Closes #15785
This commit is contained in:
parent
fa0ccd9f1f
commit
37fb50a858
15 changed files with 199 additions and 132 deletions
|
|
@ -59,6 +59,9 @@ static void startElement(void *userData, const XML_Char *name,
|
|||
state->tags++;
|
||||
state->depth++;
|
||||
|
||||
(void)name;
|
||||
(void)atts;
|
||||
|
||||
/* Get a clean slate for reading in character data. */
|
||||
free(state->characters.memory);
|
||||
state->characters.memory = NULL;
|
||||
|
|
@ -70,7 +73,7 @@ static void characterDataHandler(void *userData, const XML_Char *s, int len)
|
|||
struct ParserStruct *state = (struct ParserStruct *) userData;
|
||||
struct MemoryStruct *mem = &state->characters;
|
||||
|
||||
char *ptr = realloc(mem->memory, mem->size + len + 1);
|
||||
char *ptr = realloc(mem->memory, mem->size + (unsigned long)len + 1);
|
||||
if(!ptr) {
|
||||
/* Out of memory. */
|
||||
fprintf(stderr, "Not enough memory (realloc returned NULL).\n");
|
||||
|
|
@ -80,7 +83,7 @@ static void characterDataHandler(void *userData, const XML_Char *s, int len)
|
|||
|
||||
mem->memory = ptr;
|
||||
memcpy(&(mem->memory[mem->size]), s, len);
|
||||
mem->size += len;
|
||||
mem->size += (unsigned long)len;
|
||||
mem->memory[mem->size] = 0;
|
||||
}
|
||||
|
||||
|
|
@ -100,8 +103,8 @@ static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb,
|
|||
struct ParserStruct *state = (struct ParserStruct *) XML_GetUserData(parser);
|
||||
|
||||
/* Only parse if we are not already in a failure state. */
|
||||
if(state->ok && XML_Parse(parser, contents, real_size, 0) == 0) {
|
||||
int error_code = XML_GetErrorCode(parser);
|
||||
if(state->ok && XML_Parse(parser, contents, (int)real_size, 0) == 0) {
|
||||
enum XML_Error error_code = XML_GetErrorCode(parser);
|
||||
fprintf(stderr, "Parsing response buffer of length %lu failed"
|
||||
" with error code %d (%s).\n",
|
||||
real_size, error_code, XML_ErrorString(error_code));
|
||||
|
|
@ -147,7 +150,7 @@ int main(void)
|
|||
else if(state.ok) {
|
||||
/* Expat requires one final call to finalize parsing. */
|
||||
if(XML_Parse(parser, NULL, 0, 1) == 0) {
|
||||
int error_code = XML_GetErrorCode(parser);
|
||||
enum XML_Error error_code = XML_GetErrorCode(parser);
|
||||
fprintf(stderr, "Finalizing parsing failed with error code %d (%s).\n",
|
||||
error_code, XML_ErrorString(error_code));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue