casts: forbid empty string casts (#160)

This commit is contained in:
Tyler Wilding 2022-12-09 19:36:19 -05:00 committed by GitHub
parent ab5efa2ade
commit b23a8cc257
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -129,7 +129,7 @@ async function labelCastSelection() {
const castToType = await vscode.window.showInputBox({ const castToType = await vscode.window.showInputBox({
title: "Cast to Type?", title: "Cast to Type?",
}); });
if (castToType === undefined) { if (castToType === undefined || castToType.trim() === "") {
await vscode.window.showErrorMessage("Can't cast if no type is provided"); await vscode.window.showErrorMessage("Can't cast if no type is provided");
return; return;
} }
@ -148,7 +148,13 @@ async function labelCastSelection() {
} }
// Finally, do the cast! // Finally, do the cast!
await applyLabelCast(editor, objectName, labelRef, castToType, pointerSize); await applyLabelCast(
editor,
objectName,
labelRef,
castToType.trim(),
pointerSize
);
lastCastKind = CastKind.Label; lastCastKind = CastKind.Label;
lastLabelCastType = castToType; lastLabelCastType = castToType;
@ -214,13 +220,13 @@ async function stackCastSelection() {
const castToType = await vscode.window.showInputBox({ const castToType = await vscode.window.showInputBox({
title: "Cast to Type?", title: "Cast to Type?",
}); });
if (castToType === undefined) { if (castToType === undefined || castToType.trim() === "") {
await vscode.window.showErrorMessage("Can't cast if no type is provided"); await vscode.window.showErrorMessage("Can't cast if no type is provided");
return; return;
} }
// Finally, do the cast! // Finally, do the cast!
await applyStackCast(editor, funcName, stackOffset, castToType); await applyStackCast(editor, funcName, stackOffset, castToType.trim());
lastCastKind = CastKind.Stack; lastCastKind = CastKind.Stack;
lastStackCastType = castToType; lastStackCastType = castToType;
@ -338,7 +344,7 @@ async function typeCastSelection() {
const castToType = await vscode.window.showInputBox({ const castToType = await vscode.window.showInputBox({
title: "Cast to Type?", title: "Cast to Type?",
}); });
if (castToType === undefined) { if (castToType === undefined || castToType.trim() === "") {
await vscode.window.showErrorMessage("Can't cast if no type is provided"); await vscode.window.showErrorMessage("Can't cast if no type is provided");
return; return;
} }
@ -349,7 +355,7 @@ async function typeCastSelection() {
funcName, funcName,
castContext, castContext,
registerSelection, registerSelection,
castToType castToType.trim()
); );
lastCastKind = CastKind.TypeCast; lastCastKind = CastKind.TypeCast;