File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 1414*/
1515int register_hash (const struct ltc_hash_descriptor * hash )
1616{
17- int x ;
17+ int x , blank = -1 ;
1818
1919 LTC_ARGCHK (hash != NULL );
2020
21+ if (hash -> name == NULL )
22+ return -1 ;
23+
2124 /* is it already registered? */
2225 LTC_MUTEX_LOCK (& ltc_hash_mutex );
2326 for (x = 0 ; x < TAB_SIZE ; x ++ ) {
2427 if (XMEMCMP (& hash_descriptor [x ], hash , sizeof (struct ltc_hash_descriptor )) == 0 ) {
2528 LTC_MUTEX_UNLOCK (& ltc_hash_mutex );
2629 return x ;
2730 }
31+ if (hash_descriptor [x ].name == NULL && blank == -1 ) {
32+ blank = x ;
33+ }
2834 }
2935
30- /* find a blank spot */
31- for (x = 0 ; x < TAB_SIZE ; x ++ ) {
32- if (hash_descriptor [x ].name == NULL ) {
33- XMEMCPY (& hash_descriptor [x ], hash , sizeof (struct ltc_hash_descriptor ));
34- LTC_MUTEX_UNLOCK (& ltc_hash_mutex );
35- return x ;
36- }
36+ /* fill in blank spot */
37+ if (blank != -1 ) {
38+ XMEMCPY (& hash_descriptor [blank ], hash , sizeof (struct ltc_hash_descriptor ));
39+ LTC_MUTEX_UNLOCK (& ltc_hash_mutex );
40+ return x ;
3741 }
3842
3943 /* no spot */
You can’t perform that action at this time.
0 commit comments