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 1 commit
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)) {
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)) {
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;
}


24 changes: 13 additions & 11 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,14 +1895,15 @@ yaml_emitter_write_tag_content(yaml_emitter_t *emitter,
}
else {
int width = WIDTH(string);
unsigned int value_inner;
while (width --) {
value = *(string.pointer++);
if (!PUT(emitter, '%')) return 0;
if (!PUT(emitter, ((unsigned int)value >> 4)
+ (((unsigned int)value >> 4) < 10 ? '0' : 'A' - 10)))
if (!PUT(emitter, (value_inner >> 4)
+ ((value_inner >> 4) < 10 ? '0' : 'A' - 10)))
return 0;
if (!PUT(emitter, ((unsigned int)value & 0x0F)
+ (((unsigned int)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 @@ -2066,26 +2067,27 @@ yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter,
{
unsigned char octet;
unsigned int width;
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 = ((unsigned int)value << 6) + (octet & 0x3F);
value_inner = (value_inner << 6) + (octet & 0x3F);
}
string.pointer += width;

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

switch ((unsigned int)value)
switch (value_inner)
{
case 0x00:
if (!PUT(emitter, '0')) return 0;
Expand Down Expand Up @@ -2148,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 @@ -2161,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 = ((unsigned int)value >> k) & 0x0F;
int digit = (value_inner >> k) & 0x0F;
if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10)))
return 0;
}
Expand Down