Skip to content

Commit d93be1a

Browse files
aperezdccsaavedra
authored andcommitted
REGRESSION(308608@main): [JSC] Clang 21 reports unsafe buffer usage warnings
https://bugs.webkit.org/show_bug.cgi?id=309163 Reviewed by Claudio Saavedra. Avoid using the two parameter std::span() constructor by replacing it with unsafeMakeSpan(), and avoid the strlen() calls by letting String::fromUTF8() ingest the null-terminated strings directly. * Source/JavaScriptCore/API/glib/JSCContext.cpp: (jsc_context_evaluate_with_source_uri): (jsc_context_evaluate_in_object): (jsc_context_check_syntax): Canonical link: https://commits.webkit.org/308689@main
1 parent 26d7991 commit d93be1a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎Source/JavaScriptCore/API/glib/JSCContext.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ JSCValue* jsc_context_evaluate_with_source_uri(JSCContext* context, const char*
879879
g_return_val_if_fail(code, nullptr);
880880

881881
JSValueRef exception = nullptr;
882-
JSValueRef result = evaluateScriptInContext(context->priv->jsContext.get(), String::fromUTF8(std::span(code, length < 0 ? strlen(code) : length)), uri, lineNumber, &exception);
882+
JSValueRef result = evaluateScriptInContext(context->priv->jsContext.get(), length < 0 ? String::fromUTF8(code) : String::fromUTF8(unsafeMakeSpan(code, length)), uri, lineNumber, &exception);
883883
if (jscContextHandleExceptionIfNeeded(context, exception))
884884
return jsc_value_new_undefined(context);
885885

@@ -919,7 +919,7 @@ JSCValue* jsc_context_evaluate_in_object(JSCContext* context, const char* code,
919919
JSC::JSLockHolder locker(globalObject);
920920
globalObject->setGlobalScopeExtension(JSC::JSWithScope::create(vm, globalObject, globalObject->globalScope(), toJS(JSContextGetGlobalObject(context->priv->jsContext.get()))));
921921
JSValueRef exception = nullptr;
922-
JSValueRef result = evaluateScriptInContext(objectContext.get(), String::fromUTF8(std::span(code, length < 0 ? strlen(code) : length)), uri, lineNumber, &exception);
922+
JSValueRef result = evaluateScriptInContext(objectContext.get(), length < 0 ? String::fromUTF8(code) : String::fromUTF8(unsafeMakeSpan(code, length)), uri, lineNumber, &exception);
923923
if (jscContextHandleExceptionIfNeeded(context, exception))
924924
return jsc_value_new_undefined(context);
925925

@@ -979,7 +979,7 @@ JSCCheckSyntaxResult jsc_context_check_syntax(JSCContext* context, const char* c
979979
JSC::JSLockHolder locker(vm);
980980

981981
URL sourceURL = uri ? URL(String::fromLatin1(uri)) : URL();
982-
JSC::SourceCode source = JSC::makeSource(String::fromUTF8(std::span(code, length < 0 ? strlen(code) : length)), JSC::SourceOrigin { sourceURL }, JSC::SourceTaintedOrigin::Untainted,
982+
JSC::SourceCode source = JSC::makeSource(length < 0 ? String::fromUTF8(code) : String::fromUTF8(unsafeMakeSpan(code, length)), JSC::SourceOrigin { sourceURL }, JSC::SourceTaintedOrigin::Untainted,
983983
sourceURL.string() , TextPosition(OrdinalNumber::fromOneBasedInt(lineNumber), OrdinalNumber()));
984984
bool success = false;
985985
JSC::ParserError error;

0 commit comments

Comments
 (0)