Skip to content

Commit

Permalink
Small refactor in ada-lang.c:scan_discrim_bound
Browse files Browse the repository at this point in the history
Factor out common arithmetic operations for clarity.

gdb/ChangeLog:

	* ada-lang.c (scan_discrim_bound): Factor out arithmetic
	operations.
  • Loading branch information
Simon Marchi committed Sep 10, 2015
1 parent 108d56a commit 5da1a4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions gdb/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2015-09-10 Simon Marchi <simon.marchi@ericsson.com>

* ada-lang.c (scan_discrim_bound): Factor out arithmetic
operations.

2015-09-10 Simon Marchi <simon.marchi@ericsson.com>

* ada-lang.c (ada_search_struct_field): Constify parameters
Expand Down
17 changes: 11 additions & 6 deletions gdb/ada-lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -11432,24 +11432,29 @@ scan_discrim_bound (const char *str, int k, struct value *dval, LONGEST * px,
{
static char *bound_buffer = NULL;
static size_t bound_buffer_len = 0;
const char *pend, *bound;
const char *pstart, *pend, *bound;
struct value *bound_val;

if (dval == NULL || str == NULL || str[k] == '\0')
return 0;

pend = strstr (str + k, "__");
pstart = str + k;
pend = strstr (pstart, "__");
if (pend == NULL)
{
bound = str + k;
bound = pstart;
k += strlen (bound);
}
else
{
GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1);
int len = pend - pstart;

/* Strip __ and beyond. */
GROW_VECT (bound_buffer, bound_buffer_len, len + 1);
strncpy (bound_buffer, pstart, len);
bound_buffer[len] = '\0';

bound = bound_buffer;
strncpy (bound_buffer, str + k, pend - (str + k));
bound_buffer[pend - (str + k)] = '\0';
k = pend - str;
}

Expand Down

0 comments on commit 5da1a4d

Please sign in to comment.