VirtualBox

Changeset 1606 in kBuild


Ignore:
Timestamp:
May 8, 2008 2:44:58 AM (17 years ago)
Author:
bird
Message:

Fixed bug in append_expand_string_to_variable() where variables expansions that referenced them selves in some way would get confused by the half updated variable value. The fix temporarily switches the separtor space for a null terminator, or, in the case of an empty value, make it point to a static empty string.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/expand.c

    r1536 r1606  
    611611append_expanded_string_to_variable (struct variable *v, const char *value)
    612612{
     613  static char const empty_string[] = "";
     614  unsigned int original_value_length = v->value_length;
    613615  char *p;
    614616
    615   /* switch the variable buffer to the variable value buffer. */
     617  /* Switch the variable buffer to the variable value buffer. */
    616618  char *saved_buffer = variable_buffer;
    617619  unsigned int saved_buffer_length = variable_buffer_length;
     
    619621  variable_buffer_length = v->value_alloc_len;
    620622
    621   /* skip the current value and start appending a space and the expanded string. */
    622   p = v->value + v->value_length;
    623   if (v->value_length != 0)
     623  /* Mark the variable as being expanding. */
     624  if (v->value_alloc_len == -42)
     625    fatal (*expanding_var, _("var=%s"), v->name);
     626  assert (v->value_alloc_len >= 0);
     627  v->value_alloc_len = -42;
     628
     629  /* Skip the current value and start appending a '\0' / space before
     630     expanding the string so recursive references are handled correctly.
     631     Alternatively, if it's an empty value, replace the value with a fixed
     632     empty string. */
     633  p = v->value + original_value_length;
     634  if (original_value_length)
     635    {
    624636      p = variable_buffer_output (p, " ", 1);
     637      p[-1] = '\0';
     638    }
     639  else
     640    v->value = (char *)&empty_string[0];
    625641  p = variable_expand_string (p, value, (long)-1);
    626642
    627   /* update the variable. (The variable_expand_string return is annoying!) */
     643  /* Replace the '\0' with the space separator. */
     644  if (original_value_length)
     645    {
     646      assert (variable_buffer[original_value_length] == '\0');
     647      variable_buffer[original_value_length] = ' ';
     648    }
     649  else
     650    {
     651      assert (v->value == (char *)&empty_string[0]);
     652      assert (empty_string[0] == '\0');
     653    }
     654
     655  /* Update the variable. (mind the variable_expand_string() return) */
    628656  p = strchr (p, '\0');
    629657  v->value = variable_buffer;
     
    631659  v->value_alloc_len = variable_buffer_length;
    632660
    633   /* restore the variable buffer. */
     661  /* Restore the variable buffer. */
    634662  variable_buffer = saved_buffer;
    635663  variable_buffer_length = saved_buffer_length;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette