Подробности
        
                          [В начало]
Проблема в реализации № S0790
Краткое описание
hsearch_r() падает при попытке вставить второе значение в 2-х элементный хеш
Подробное описание
Eсли инициализировать хэш функцией hcreate_r() с параметром nel = 0 или 1, то попытка вставить в него второе значение ключа при помощи hsearch_r() приведет к падению. Эта проблема появилась в результате изменения в функции hsearch_r() [1], которые были внесены в glibc-2.9, и уже была исправлена в cvs glibc:
/* There is still another table active. Return with error. */
   if (htab->table != NULL)
     return 0;
 
+  /* We need a size of at least 3.  Otherwise the hash functions we
+     use will not work.  */
+  if (nel < 3)
+    nel = 3;
   /* Change nel to the first prime number not smaller as nel. */
   nel |= 1;      /* make odd */
   while (!isprime (nel))
     nel += 2;
но ещё присутствует в glibc-2.9 и, в частности, в Ubuntu-9.04. Пример, приведённый ниже, демонстрирует данную проблему.
[1] http://sourceware.org/bugzilla/show_bug.cgi?id=6966
Раздел стандарта
Linux Standard Base Core Specification 3.1, Chapter 13. Base Libraries, 13.3. Interfaces for libc, 13.3.17. Standard Library, 13.3.17.1. Interfaces for Standard Library, Table 13-22. libc - Standard Library Function Interfaces, descriptions of hcreate(), hsearch() and hdestroy() functions.
Пример
#include <stdio.h>
#include <search.h>
int main()
{
	char * key[] = { "key1", "key2" };
	char * data = "data";
	int i;
	ENTRY item;
	item.data = data;
	hcreate(1); // nel = 0 or 1
	for(i = 0; i < 2; i++){
		item.key = key[i];
		printf("try to insert '%s'='%s'
", item.key, (char *)item.data);
		hsearch(item, ENTER);
		printf("successful
");
	}
	hdestroy();
	return 0;
}
                    Компонент
glibc 2.9
Статус
Исправлено в glibc-2.10
[В начало]