Skip to content

Is ByteConversionSink.add() really not safe? #29336

Open
@sgrekhov

Description

@sgrekhov

Please see ByteConversionSink.addSlice() documentation https://api.dartlang.org/stable/1.22.1/dart-convert/ByteConversionSink/addSlice.html

Contrary to add the given chunk must not be held onto. Once the method returns, it is safe to overwrite the data in it.

The above means that it is unsafe to overwrite the data if add() is used instead of addSlice(). But I can't see that

import "dart:convert";
main() {
  var outSink = new ChunkedConversionSink.withCallback((accumulated) {
    print(accumulated);
  });

  ByteConversionSink inSink = UTF8.decoder.startChunkedConversion(outSink);
  var list = UTF8.encode("Кириллица");

  inSink.add(list);
  // Now change the data, lowercase the first letter to к
  list[0] = 0xd0;
  list[1] = 0xba;
  inSink.add(list);
  inSink.close(); // prints [Кириллица, кириллица]
}

Seems that all is safe

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-alibrary-converttype-documentationA request to add or improve documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions