mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Fixed a crash with negative hash ids (made them unsigned)
This commit is contained in:
parent
1e63fa4174
commit
1f631bf667
12
tools.c
12
tools.c
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* how to reach the author.
|
||||
*
|
||||
* $Id: tools.c 1.94 2005/05/28 11:46:44 kls Exp $
|
||||
* $Id: tools.c 1.95 2005/05/29 10:18:26 kls Exp $
|
||||
*/
|
||||
|
||||
#include "tools.h"
|
||||
@ -1075,15 +1075,15 @@ cHashBase::~cHashBase(void)
|
||||
free(hashTable);
|
||||
}
|
||||
|
||||
void cHashBase::Add(cListObject *Object, int Id)
|
||||
void cHashBase::Add(cListObject *Object, unsigned int Id)
|
||||
{
|
||||
int hash = hashfn(Id);
|
||||
unsigned int hash = hashfn(Id);
|
||||
if (!hashTable[hash])
|
||||
hashTable[hash] = new cList<cHashObject>;
|
||||
hashTable[hash]->Add(new cHashObject(Object, Id));
|
||||
}
|
||||
|
||||
void cHashBase::Del(cListObject *Object, int Id)
|
||||
void cHashBase::Del(cListObject *Object, unsigned int Id)
|
||||
{
|
||||
cList<cHashObject> *list = hashTable[hashfn(Id)];
|
||||
if (list) {
|
||||
@ -1096,7 +1096,7 @@ void cHashBase::Del(cListObject *Object, int Id)
|
||||
}
|
||||
}
|
||||
|
||||
cListObject *cHashBase::Get(int Id) const
|
||||
cListObject *cHashBase::Get(unsigned int Id) const
|
||||
{
|
||||
cList<cHashObject> *list = hashTable[hashfn(Id)];
|
||||
if (list) {
|
||||
@ -1108,7 +1108,7 @@ cListObject *cHashBase::Get(int Id) const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cList<cHashObject> *cHashBase::GetList(int Id) const
|
||||
cList<cHashObject> *cHashBase::GetList(unsigned int Id) const
|
||||
{
|
||||
return hashTable[hashfn(Id)];
|
||||
}
|
||||
|
18
tools.h
18
tools.h
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* how to reach the author.
|
||||
*
|
||||
* $Id: tools.h 1.71 2005/05/28 11:24:49 kls Exp $
|
||||
* $Id: tools.h 1.72 2005/05/29 10:24:54 kls Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TOOLS_H
|
||||
@ -239,25 +239,25 @@ public:
|
||||
class cHashObject : public cListObject {
|
||||
friend class cHashBase;
|
||||
private:
|
||||
int id;
|
||||
unsigned int id;
|
||||
cListObject *object;
|
||||
public:
|
||||
cHashObject(cListObject *Object, int Id) { object = Object; id = Id; }
|
||||
cHashObject(cListObject *Object, unsigned int Id) { object = Object; id = Id; }
|
||||
};
|
||||
|
||||
class cHashBase {
|
||||
private:
|
||||
cList<cHashObject> **hashTable;
|
||||
int size;
|
||||
int hashfn(int Id) const { return Id % size; }
|
||||
unsigned int hashfn(unsigned int Id) const { return Id % size; }
|
||||
protected:
|
||||
cHashBase(int Size);
|
||||
public:
|
||||
virtual ~cHashBase();
|
||||
void Add(cListObject *Object, int Id);
|
||||
void Del(cListObject *Object, int Id);
|
||||
cListObject *Get(int Id) const;
|
||||
cList<cHashObject> *GetList(int Id) const;
|
||||
void Add(cListObject *Object, unsigned int Id);
|
||||
void Del(cListObject *Object, unsigned int Id);
|
||||
cListObject *Get(unsigned int Id) const;
|
||||
cList<cHashObject> *GetList(unsigned int Id) const;
|
||||
};
|
||||
|
||||
#define HASHSIZE 512
|
||||
@ -265,7 +265,7 @@ public:
|
||||
template<class T> class cHash : public cHashBase {
|
||||
public:
|
||||
cHash(int Size = HASHSIZE) : cHashBase(Size) {}
|
||||
T *Get(int Id) const { return (T *)cHashBase::Get(Id); }
|
||||
T *Get(unsigned int Id) const { return (T *)cHashBase::Get(Id); }
|
||||
};
|
||||
|
||||
#endif //__TOOLS_H
|
||||
|
Loading…
Reference in New Issue
Block a user