From: Simon Marchi Date: Thu, 10 Sep 2015 15:48:47 +0000 (-0400) Subject: Small refactor in ada-lang.c:scan_discrim_bound X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5da1a4d34e730e0b4e2f034c81d22d5948a6ce67;p=binutils-gdb.git Small refactor in ada-lang.c:scan_discrim_bound Factor out common arithmetic operations for clarity. gdb/ChangeLog: * ada-lang.c (scan_discrim_bound): Factor out arithmetic operations. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b72031a485a..2404edd6627 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2015-09-10 Simon Marchi + + * ada-lang.c (scan_discrim_bound): Factor out arithmetic + operations. + 2015-09-10 Simon Marchi * ada-lang.c (ada_search_struct_field): Constify parameters diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index a514f655bdc..d166d1cba02 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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; }