ovsdb-idl: Check if row->written is valid.
authorJesse Gross <jesse@nicira.com>
Thu, 24 Jun 2010 22:31:18 +0000 (15:31 -0700)
committerJesse Gross <jesse@nicira.com>
Thu, 24 Jun 2010 22:48:03 +0000 (15:48 -0700)
Commit cde3f1 "ovsdb-idl: Drop unnecessary allocation from
ovsdb_idl_txn_insert()." does lazy allocation of row->written
on the assumption that ovsdb_idl_txn_write() will handle it.
However, this isn't the case for empty rows created by something
like "ovs-vsctl init" so add a check before reading the bitfield.

lib/ovsdb-idl.c

index aa2f2ce71a9961dc699596d4683ecd50f45ba588..62a33609ec599c2c44b627b54affedf23c55e53b 100644 (file)
@@ -670,8 +670,10 @@ ovsdb_idl_row_clear_new(struct ovsdb_idl_row *row)
             const struct ovsdb_idl_table_class *class = row->table->class;
             size_t i;
 
-            BITMAP_FOR_EACH_1 (i, class->n_columns, row->written) {
-                ovsdb_datum_destroy(&row->new[i], &class->columns[i].type);
+            if (row->written) {
+                BITMAP_FOR_EACH_1 (i, class->n_columns, row->written) {
+                    ovsdb_datum_destroy(&row->new[i], &class->columns[i].type);
+                }
             }
             free(row->new);
             free(row->written);
@@ -1233,18 +1235,22 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
             row_json = json_object_create();
             json_object_put(op, "row", row_json);
 
-            BITMAP_FOR_EACH_1 (idx, class->n_columns, row->written) {
-                const struct ovsdb_idl_column *column = &class->columns[idx];
-
-                if (row->old
-                    ? !ovsdb_datum_equals(&row->old[idx], &row->new[idx],
-                                          &column->type)
-                    : !ovsdb_datum_is_default(&row->new[idx], &column->type)) {
-                    json_object_put(row_json, column->name,
-                                    substitute_uuids(
-                                        ovsdb_datum_to_json(&row->new[idx],
-                                                            &column->type),
-                                        txn));
+            if (row->written) {
+                BITMAP_FOR_EACH_1 (idx, class->n_columns, row->written) {
+                    const struct ovsdb_idl_column *column =
+                                                        &class->columns[idx];
+
+                    if (row->old
+                        ? !ovsdb_datum_equals(&row->old[idx], &row->new[idx],
+                                              &column->type)
+                        : !ovsdb_datum_is_default(&row->new[idx],
+                                                  &column->type)) {
+                        json_object_put(row_json, column->name,
+                                        substitute_uuids(
+                                            ovsdb_datum_to_json(&row->new[idx],
+                                                                &column->type),
+                                            txn));
+                    }
                 }
             }