On Thu, Sep 5, 2013 at 3:11 PM, <[email protected]> wrote: > Eliminate mutable String in Util::Freezer
> Project: http://git-wip-us.apache.org/repos/asf/lucy/repo > Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/cfea9e61 > Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/cfea9e61 > Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/cfea9e61 > Hash_init(hash, size); > > // Read key-value pairs with String keys. > while (num_strings--) { > uint32_t len = InStream_Read_C32(instream); > - char *key_buf = Str_Grow(key, len); > + char *key_buf = (char*)MALLOCATE(len + 1); > InStream_Read_Bytes(instream, key_buf, len); > key_buf[len] = '\0'; > - Str_Set_Size(key, len); > + String *key = Str_new_steal_from_trusted_str(key_buf, len, len + 1); > Hash_Store(hash, (Obj*)key, THAW(instream)); > + DECREF(key); > } When reading the key, we should use a constructor which validates incoming UTF-8 rather than Str_new_steal_from_trusted_str because we don't know (and therefore don't "trust") the origin of the bytes we're deserializing. Marvin Humphrey
