Fixed invalid use of STL vector. I wonder, why I always involuntarily

shudder when looking into MDR code (and happily use Beam). Error
checking, anyone?


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15257 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2005-11-30 23:55:02 +00:00
parent 9a8ef58959
commit b22fc00fa8

View File

@ -1,9 +1,8 @@
#include "NodeMessage.h" #include "NodeMessage.h"
#include <StorageKit.h> #include <StorageKit.h>
#include <fs_attr.h> #include <fs_attr.h>
#include <vector> #include <stdlib.h>
using std::vector;
/* /*
These functions gives a nice BMessage interface to node attributes, These functions gives a nice BMessage interface to node attributes,
by letting you transfer attributes to and from BMessages. It makes by letting you transfer attributes to and from BMessages. It makes
@ -43,18 +42,27 @@ _EXPORT BNode& operator>>(BNode& n, BMessage& m)
{ {
char name[B_ATTR_NAME_LENGTH]; char name[B_ATTR_NAME_LENGTH];
attr_info info; attr_info info;
vector<char> buf(4); char *buf = NULL;
n.RewindAttrs(); n.RewindAttrs();
while (n.GetNextAttrName(name)==B_OK) while (n.GetNextAttrName(name)==B_OK)
{ {
n.GetAttrInfo(name,&info); if (n.GetAttrInfo(name,&info) != B_OK)
buf.resize(info.size); continue;
info.size=n.ReadAttr(name,info.type,0,buf.begin(),info.size);
// resize the buffer
if (char *newBuffer = (char*)realloc(buf, info.size))
buf = newBuffer;
else
continue;
info.size=n.ReadAttr(name,info.type,0,buf,info.size);
if (info.size >= 0) if (info.size >= 0)
m.AddData(name,info.type,buf.begin(),info.size); m.AddData(name,info.type,buf,info.size);
} }
n.RewindAttrs(); n.RewindAttrs();
free(buf);
return n; return n;
} }