Skip to content

Commit

Permalink
console: argtable3: upgrade to v3.2.2
Browse files Browse the repository at this point in the history
Closes #9907
Closes #10016
  • Loading branch information
igrr committed Nov 9, 2022
1 parent 166effd commit fc0f640
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
4 changes: 3 additions & 1 deletion components/console/argtable3/arg_rex.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ typedef struct {
int len;
} TRexMatch;

#ifdef __GNUC__
#if defined(__clang__)
TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags) __attribute__((optnone));
#elif defined(__GNUC__)
TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags) __attribute__((optimize(0)));
#else
TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags);
Expand Down
33 changes: 23 additions & 10 deletions components/console/argtable3/argtable3.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ static void arg_cat(char** pdest, const char* src, size_t* pndest) {
char* end = dest + *pndest;

/*locate null terminator of dest string */
while (dest < end && *dest != 0)
while (dest < end-1 && *dest != 0)
dest++;

/* concat src string to dest string */
while (dest < end && *src != 0)
while (dest < end-1 && *src != 0)
*dest++ = *src++;

/* null terminate dest string */
Expand Down Expand Up @@ -887,8 +887,8 @@ static void arg_print_formatted_ds(arg_dstr_t ds, const unsigned lmargin, const
while (line_end > line_start) {
/* Eat leading white spaces. This is essential because while
wrapping lines, there will often be a whitespace at beginning
of line */
while (isspace((int)(*(text + line_start)))) {
of line. Preserve newlines */
while (isspace((int)(*(text + line_start))) && *(text + line_start) != '\n') {
line_start++;
}

Expand All @@ -900,18 +900,31 @@ static void arg_print_formatted_ds(arg_dstr_t ds, const unsigned lmargin, const
line_end--;
}

/* Consume trailing spaces */
while ((line_end > line_start) && isspace((int)(*(text + line_end)))) {
line_end--;
}
/* If no whitespace could be found, eg. the text is one long word, break the word */
if (line_end == line_start) {
/* Set line_end to previous value */
line_end = line_start + colwidth;
} else {
/* Consume trailing spaces, except newlines */
while ((line_end > line_start) && isspace((int)(*(text + line_end))) && *(text + line_start) != '\n') {
line_end--;
}

/* Restore the last non-space character */
line_end++;
/* Restore the last non-space character */
line_end++;
}
}

/* Output line of text */
while (line_start < line_end) {
char c = *(text + line_start);

/* If character is newline stop printing, skip this character, as a newline will be printed below. */
if (c == '\n') {
line_start++;
break;
}

arg_dstr_catc(ds, c);
line_start++;
}
Expand Down

0 comments on commit fc0f640

Please sign in to comment.