X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=blob.c;h=4ecbc45bb15f42c15342e7900f4de94522ef45bb;hp=e10b522f73a249f5b02b6f50b72788efdc6d7f68;hb=742be1f7334570492615fdf89ce46123e3f71886;hpb=53fe3c3cca7caef5565750181daf70aa0598c2a9 diff --git a/blob.c b/blob.c index e10b522f..4ecbc45b 100644 --- a/blob.c +++ b/blob.c @@ -103,7 +103,7 @@ static int print_blob(struct osl_table *table, struct osl_row *row, para_printf(&aca->pbout, "cannot list %s\n", name); return ret; } - id = *(uint32_t *)obj.data; + id = read_u32(obj.data); para_printf(&aca->pbout, "%u\t%s\n", id, name); return 1; } @@ -266,7 +266,8 @@ static int com_addblob_callback(__a_unused const struct lls_command * const cmd, struct osl_object objs[NUM_BLOB_COLUMNS]; char *name = aca->query.data; size_t name_len = strlen(name) + 1; - uint32_t id; + uint32_t id = (uint32_t)-1; /* STFU, gcc */ + char id_buf[sizeof(id)]; unsigned num_rows; int ret; @@ -274,10 +275,15 @@ static int com_addblob_callback(__a_unused const struct lls_command * const cmd, if (ret < 0) goto out; if (!num_rows) { /* this is the first entry ever added */ - /* insert dummy row containing the id */ - id = 2; /* this entry will be entry #1, so 2 is the next */ - objs[BLOBCOL_ID].data = &id; - objs[BLOBCOL_ID].size = sizeof(id); + /* + * Insert dummy row containing the next free ID. Since we are + * about to insert the first blob with ID 1, the next free ID + * will be 2. + */ + id = 2U; + write_u32(id_buf, id); + objs[BLOBCOL_ID].data = id_buf; + objs[BLOBCOL_ID].size = sizeof(id_buf); objs[BLOBCOL_NAME].data = ""; objs[BLOBCOL_NAME].size = 1; objs[BLOBCOL_DEF].data = ""; @@ -296,7 +302,7 @@ static int com_addblob_callback(__a_unused const struct lls_command * const cmd, ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj)); if (ret < 0) goto out; - id = *(uint32_t *)obj.data; + id = read_u32(obj.data); obj.data = name + name_len; obj.size = aca->query.size - name_len; ret = osl(osl_update_object(table, row, BLOBCOL_DEF, &obj)); @@ -311,15 +317,17 @@ static int com_addblob_callback(__a_unused const struct lls_command * const cmd, ret = osl(osl_get_object(table, row, BLOBCOL_ID, &obj)); if (ret < 0) goto out; - id = *(uint32_t *)obj.data + 1; - obj.data = &id; + id = read_u32(obj.data) + 1; + write_u32(id_buf, id); + obj.data = &id_buf; ret = osl(osl_update_object(table, row, BLOBCOL_ID, &obj)); if (ret < 0) goto out; } id--; - objs[BLOBCOL_ID].data = &id; - objs[BLOBCOL_ID].size = sizeof(id); + write_u32(id_buf, id); + objs[BLOBCOL_ID].data = &id_buf; + objs[BLOBCOL_ID].size = sizeof(id_buf); objs[BLOBCOL_NAME].data = name; objs[BLOBCOL_NAME].size = name_len; objs[BLOBCOL_DEF].data = name + name_len;