mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 12:19:09 -04:00
refactor: use explicit string length when converting from buffer to Dart string
This commit is contained in:
parent
f4e9ae4167
commit
0a758b771a
7 changed files with 22 additions and 22 deletions
|
@ -224,7 +224,7 @@ String remoteName({
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ String upstreamName({
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ String upstreamRemote({
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ String upstreamMerge({
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -51,14 +51,14 @@ Pointer<git_config> openDefault() {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
String findGlobal() {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_config_find_global(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ String findSystem() {
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ String findXdg() {
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ String format({
|
|||
bool? alwaysUseLongFormat,
|
||||
String? dirtySuffix,
|
||||
}) {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final opts = calloc<git_describe_format_options>();
|
||||
libgit2.git_describe_format_options_init(
|
||||
opts,
|
||||
|
@ -104,7 +104,7 @@ String format({
|
|||
|
||||
libgit2.git_describe_format(out, describeResultPointer, opts);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
calloc.free(opts);
|
||||
calloc.free(out);
|
||||
|
|
|
@ -352,14 +352,14 @@ String statsPrint({
|
|||
required int format,
|
||||
required int width,
|
||||
}) {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -218,14 +218,14 @@ Pointer<git_diff_line> lines({
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
String text(Pointer<git_patch> patch) {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_patch_to_buf(out, patch);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ String transform({
|
|||
required Pointer<git_refspec> refspecPointer,
|
||||
required String name,
|
||||
}) {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_refspec_transform(out, refspecPointer, nameC);
|
||||
|
||||
|
@ -72,7 +72,7 @@ String transform({
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ String rTransform({
|
|||
required Pointer<git_refspec> refspecPointer,
|
||||
required String name,
|
||||
}) {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_refspec_rtransform(out, refspecPointer, nameC);
|
||||
|
||||
|
@ -96,7 +96,7 @@ String rTransform({
|
|||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ String discover({
|
|||
required String startPath,
|
||||
String? ceilingDirs,
|
||||
}) {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final startPathC = startPath.toNativeUtf8().cast<Int8>();
|
||||
final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||
|
||||
|
@ -49,7 +49,7 @@ String discover({
|
|||
calloc.free(startPathC);
|
||||
calloc.free(ceilingDirsC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
@ -389,14 +389,14 @@ bool isWorktree(Pointer<git_repository> repo) {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
String message(Pointer<git_repository> repo) {
|
||||
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_repository_message(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue