mirror of
https://github.com/git/git.git
synced 2024-11-19 04:04:17 +01:00
812666c8e6
Introduce xmalloc and xrealloc to die gracefully with a descriptive message when out of memory, rather than taking a SIGSEGV. Signed-off-by: Christopher Li<chrislgit@chrisli.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
24 lines
548 B
C
24 lines
548 B
C
#include "blob.h"
|
|
#include "cache.h"
|
|
#include <stdlib.h>
|
|
|
|
const char *blob_type = "blob";
|
|
|
|
struct blob *lookup_blob(unsigned char *sha1)
|
|
{
|
|
struct object *obj = lookup_object(sha1);
|
|
if (!obj) {
|
|
struct blob *ret = xmalloc(sizeof(struct blob));
|
|
memset(ret, 0, sizeof(struct blob));
|
|
created_object(sha1, &ret->object);
|
|
ret->object.type = blob_type;
|
|
return ret;
|
|
}
|
|
if (obj->parsed && obj->type != blob_type) {
|
|
error("Object %s is a %s, not a blob",
|
|
sha1_to_hex(sha1), obj->type);
|
|
return NULL;
|
|
}
|
|
return (struct blob *) obj;
|
|
}
|