~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Monty Taylor
  • Date: 2008-12-08 07:41:44 UTC
  • mto: This revision was merged to the branch mainline in revision 670.
  • Revision ID: monty@inaugust.com-20081208074144-bcv10c8p9g1h2n0z
Got closer...

Show diffs side-by-side

added added

removed removed

Lines of Context:
549
549
*/
550
550
 
551
551
bool update_sys_var_str(sys_var_str *var_str, pthread_rwlock_t *var_mutex,
552
 
                        set_var *var)
 
552
                        set_var *var)
553
553
{
554
554
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
555
555
  uint32_t new_length= (var ? var->value->str_value.length() : 0);
556
556
  if (!old_value)
557
557
    old_value= (char*) "";
558
 
  res= (char *)malloc(new_length);
 
558
  res= (char *)malloc(new_length + 1);
559
559
  if (res == NULL)
560
560
    return 1;
561
 
  strncpy(res, old_value, new_length);
 
561
  memcpy(res, old_value, new_length);
 
562
  res[new_length]= 0; 
562
563
 
563
564
  /*
564
565
    Replace the old value in such a way that the any thread using
1934
1935
    old_value= make_default_log_name(buff, log_ext);
1935
1936
    str_length= strlen(old_value);
1936
1937
  }
1937
 
  res= (char *)malloc(str_length);
 
1938
  res= (char *)malloc(str_length + 1);
1938
1939
  if (res == NULL)
1939
1940
  {
1940
1941
    result= 1;
1941
1942
    goto err;
1942
1943
  }
1943
 
  strncpy(res, old_value, str_length);
 
1944
  memcpy(res, old_value, str_length);
 
1945
  res[str_length]= 0;
1944
1946
 
1945
1947
  pthread_mutex_lock(&LOCK_global_system_variables);
1946
1948
 
2510
2512
}
2511
2513
 
2512
2514
 
 
2515
NAMED_LIST::NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
 
2516
                       uint32_t name_length_arg, unsigned char* data_arg)
 
2517
    :data(data_arg)
 
2518
{
 
2519
  name.assign(name_arg, name_length_arg);
 
2520
  links->push_back(this);
 
2521
}
 
2522
 
 
2523
 
 
2524
bool NAMED_LIST::cmp(const char *name_cmp, uint32_t length)
 
2525
{
 
2526
  return length == name.length() && !name.compare(name_cmp);
 
2527
}
 
2528
 
 
2529
 
2513
2530
/*
2514
2531
  Initialize the system variables
2515
2532
 
2939
2956
  NAMED_LIST *element;
2940
2957
  while ((element= list->get()))
2941
2958
  {
2942
 
    (*free_element)(element->name, element->data);
 
2959
    (*free_element)(element->name.c_str(), element->data);
2943
2960
    delete element;
2944
2961
  }
2945
2962
  return;
3007
3024
  while ((element= it++))
3008
3025
  {
3009
3026
    KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3010
 
    func(element->name, key_cache);
 
3027
    func(element->name.c_str(), key_cache);
3011
3028
  }
3012
3029
  return 0;
3013
3030
}