Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pedantic toolchain warnings. #229

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ yaml_stack_extend(void **start, void **top, void **end)
void *new_start;

if ((char *)*end - (char *)*start >= INT_MAX / 2)
return 0;
return 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the indent broken?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. Another reason to fully use 4 spaces / tab / {}, so autoformating tools will not struggle


new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);

Expand Down Expand Up @@ -762,9 +762,9 @@ yaml_document_start_event_initialize(yaml_event_t *event,
error:
yaml_free(version_directive_copy);
while (!STACK_EMPTY(context, tag_directives_copy)) {
yaml_tag_directive_t value = POP(context, tag_directives_copy);
yaml_free(value.handle);
yaml_free(value.prefix);
yaml_tag_directive_t value_inner = POP(context, tag_directives_copy);
yaml_free(value_inner.handle);
yaml_free(value_inner.prefix);
}
STACK_DEL(context, tag_directives_copy);
yaml_free(value.handle);
Expand Down Expand Up @@ -1104,9 +1104,9 @@ yaml_document_initialize(yaml_document_t *document,
STACK_DEL(&context, nodes);
yaml_free(version_directive_copy);
while (!STACK_EMPTY(&context, tag_directives_copy)) {
yaml_tag_directive_t value = POP(&context, tag_directives_copy);
yaml_free(value.handle);
yaml_free(value.prefix);
yaml_tag_directive_t value_inner = POP(&context, tag_directives_copy);
yaml_free(value_inner.handle);
yaml_free(value_inner.prefix);
}
STACK_DEL(&context, tag_directives_copy);
yaml_free(value.handle);
Expand Down Expand Up @@ -1389,5 +1389,3 @@ yaml_document_append_mapping_pair(yaml_document_t *document,

return 1;
}


26 changes: 13 additions & 13 deletions src/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define PUT(emitter,value) \
(FLUSH(emitter) \
&& (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \
emitter->column++, \
emitter->column++, \
1))

/*
Expand Down Expand Up @@ -1895,15 +1895,15 @@ yaml_emitter_write_tag_content(yaml_emitter_t *emitter,
}
else {
int width = WIDTH(string);
unsigned int value;
unsigned int value_inner;
while (width --) {
value = *(string.pointer++);
if (!PUT(emitter, '%')) return 0;
if (!PUT(emitter, (value >> 4)
+ ((value >> 4) < 10 ? '0' : 'A' - 10)))
if (!PUT(emitter, (value_inner >> 4)
+ ((value_inner >> 4) < 10 ? '0' : 'A' - 10)))
return 0;
if (!PUT(emitter, (value & 0x0F)
+ ((value & 0x0F) < 10 ? '0' : 'A' - 10)))
if (!PUT(emitter, (value_inner & 0x0F)
+ ((value_inner & 0x0F) < 10 ? '0' : 'A' - 10)))
return 0;
}
}
Expand Down Expand Up @@ -2067,27 +2067,27 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter,
{
unsigned char octet;
unsigned int width;
unsigned int value;
unsigned int value_inner;
int k;

octet = string.pointer[0];
width = (octet & 0x80) == 0x00 ? 1 :
(octet & 0xE0) == 0xC0 ? 2 :
(octet & 0xF0) == 0xE0 ? 3 :
(octet & 0xF8) == 0xF0 ? 4 : 0;
value = (octet & 0x80) == 0x00 ? octet & 0x7F :
value_inner = (octet & 0x80) == 0x00 ? octet & 0x7F :
(octet & 0xE0) == 0xC0 ? octet & 0x1F :
(octet & 0xF0) == 0xE0 ? octet & 0x0F :
(octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;
for (k = 1; k < (int)width; k ++) {
octet = string.pointer[k];
value = (value << 6) + (octet & 0x3F);
value_inner = (value_inner << 6) + (octet & 0x3F);
}
string.pointer += width;

if (!PUT(emitter, '\\')) return 0;

switch (value)
switch (value_inner)
{
case 0x00:
if (!PUT(emitter, '0')) return 0;
Expand Down Expand Up @@ -2150,11 +2150,11 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter,
break;

default:
if (value <= 0xFF) {
if (value_inner <= 0xFF) {
if (!PUT(emitter, 'x')) return 0;
width = 2;
}
else if (value <= 0xFFFF) {
else if (value_inner <= 0xFFFF) {
if (!PUT(emitter, 'u')) return 0;
width = 4;
}
Expand All @@ -2163,7 +2163,7 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter,
width = 8;
}
for (k = (width-1)*4; k >= 0; k -= 4) {
int digit = (value >> k) & 0x0F;
int digit = (value_inner >> k) & 0x0F;
if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10)))
return 0;
}
Expand Down
8 changes: 7 additions & 1 deletion tests/run-dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#define BUFFER_SIZE 65536
#define MAX_DOCUMENTS 16

int copy_document(yaml_document_t *document_to, yaml_document_t *document_from);
int compare_nodes(yaml_document_t *document1, int index1,
yaml_document_t *document2, int index2, int level);
int compare_documents(yaml_document_t *document1, yaml_document_t *document2);
int print_output(char *name, unsigned char *buffer, size_t size, int count);

int copy_document(yaml_document_t *document_to, yaml_document_t *document_from)
{
yaml_node_t *node;
Expand Down Expand Up @@ -302,7 +308,7 @@ main(int argc, char *argv[])
yaml_parser_delete(&parser);
}

for (k = 0; k < document_number; k ++) {
for (k = 0; k < (int)document_number; k ++) {
malyjak marked this conversation as resolved.
Show resolved Hide resolved
yaml_document_delete(documents+k);
}

Expand Down
1 change: 0 additions & 1 deletion tests/run-emitter-test-suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ int main(int argc, char *argv[])
}
else if (strncmp(line, "=VAL", 4) == 0) {
char value[1024];
int style;

get_value(line, value, &style);
implicit = (get_tag(line, tag) == NULL);
Expand Down
6 changes: 5 additions & 1 deletion tests/run-emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#define BUFFER_SIZE 65536
#define MAX_EVENTS 1024

int copy_event(yaml_event_t *event_to, yaml_event_t *event_from);
int compare_events(yaml_event_t *event1, yaml_event_t *event2);
int print_output(char *name, unsigned char *buffer, size_t size, int count);

int copy_event(yaml_event_t *event_to, yaml_event_t *event_from)
{
switch (event_from->type)
Expand Down Expand Up @@ -315,7 +319,7 @@ main(int argc, char *argv[])
yaml_parser_delete(&parser);
}

for (k = 0; k < event_number; k ++) {
for (k = 0; k < (int)event_number; k ++) {
malyjak marked this conversation as resolved.
Show resolved Hide resolved
yaml_event_delete(events+k);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-parser-test-suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void print_escaped(yaml_char_t * str, size_t length)
int i;
char c;

for (i = 0; i < length; i++) {
for (i = 0; i < (int)length; i++) {
c = *(str + i);
if (c == '\\')
printf("\\\\");
Expand Down
7 changes: 6 additions & 1 deletion tests/test-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ test_case boms[] = {

char *bom_original = "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82";

int check_utf8_sequences(void);
int check_boms(void);
int check_long_utf8(void);
int check_long_utf16(void);

int check_utf8_sequences(void)
{
yaml_parser_t parser;
Expand Down Expand Up @@ -184,7 +189,7 @@ int check_boms(void)
failed++;
}
else {
if (parser.unread != check) {
if ((int)parser.unread != check) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, avoid casts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast still needs to be there, to avoid compiler warnings. However, I improved the logic. Please see the new line 187.

printf("- (length=%ld while expected length=%d)\n", (long)parser.unread, check);
failed++;
}
Expand Down