Appease the analyzer, but also how did this ever work?

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4818 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2024-01-31 02:04:10 +00:00
parent 81c66bdddd
commit 7f661d9af9

View File

@ -121,21 +121,21 @@ static int8_t _serialize_readInt8(const char** buffer, size_t* size)
int32_t _serialize_readInt32(const char** buffer, size_t* size)
{
int32_t result;
int32_t result = 0;
_serialize_read(buffer, size, &result, sizeof(result));
return result;
}
int64_t _serialize_readInt64(const char** buffer, size_t* size)
{
int64_t result;
int64_t result = 0;
_serialize_read(buffer, size, &result, sizeof(result));
return result;
}
double _serialize_readDouble(const char** buffer, size_t* size)
{
double result;
double result = 0;
_serialize_read(buffer, size, &result, sizeof(result));
return result;
}
@ -229,7 +229,7 @@ static bool _serialize_storeInternal(tf_task_t* task, tf_taskstub_t* to, buffer_
}
else if (!JS_IsException((typed = tf_util_try_get_typed_array_buffer(context, value, &offset, &size, &element_size))))
{
size_t total_size;
size_t total_size = 0;
uint8_t* bytes = tf_util_try_get_array_buffer(context, &total_size, typed);
_serialize_writeInt32(buffer, kArrayBuffer);
_serialize_writeInt32(buffer, (int32_t)size);
@ -332,104 +332,100 @@ static JSValue _serialize_loadInternal(tf_task_t* task, tf_taskstub_t* from, con
{
return JS_UNDEFINED;
}
else
{
JSContext* context = tf_task_get_context(task);
int32_t type = _serialize_readInt32(buffer, size);
JSValue result = JS_UNDEFINED;
switch (type)
JSContext* context = tf_task_get_context(task);
int32_t type = _serialize_readInt32(buffer, size);
JSValue result = JS_UNDEFINED;
switch (type)
{
case kUndefined:
result = JS_UNDEFINED;
break;
case kNull:
result = JS_NULL;
break;
case kUninitialized:
result = JS_UNINITIALIZED;
break;
case kBoolean:
result = JS_NewBool(context, _serialize_readInt8(buffer, size) != 0);
break;
case kInt32:
result = JS_NewInt32(context, _serialize_readInt32(buffer, size));
break;
case kInt64:
result = JS_NewInt64(context, _serialize_readInt64(buffer, size));
break;
case kNumber:
result = JS_NewFloat64(context, _serialize_readDouble(buffer, size));
break;
case kString:
{
case kUndefined:
result = JS_UNDEFINED;
break;
case kNull:
result = JS_NULL;
break;
case kUninitialized:
result = JS_UNINITIALIZED;
break;
case kBoolean:
result = JS_NewBool(context, _serialize_readInt8(buffer, size) != 0);
break;
case kInt32:
result = JS_NewInt32(context, _serialize_readInt32(buffer, size));
break;
case kInt64:
result = JS_NewInt64(context, _serialize_readInt64(buffer, size));
break;
case kNumber:
result = JS_NewFloat64(context, _serialize_readDouble(buffer, size));
break;
case kString:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewStringLen(context, *buffer, length);
*buffer += length;
*size -= length;
}
break;
case kArrayBuffer:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewArrayBufferCopy(context, (const uint8_t*)*buffer, length);
*buffer += length;
*size -= length;
}
break;
case kArray:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewArray(context);
for (int i = 0; i < length; ++i)
{
JS_SetPropertyUint32(context, result, i, _serialize_loadInternal(task, from, buffer, size, depth + 1));
}
}
break;
case kFunction:
{
exportid_t exportId = _serialize_readInt32(buffer, size);
result = tf_task_add_import(task, tf_taskstub_get_id(from), exportId);
}
break;
case kException:
{
_serialize_readInt32(buffer, size);
JSValue error = JS_NewError(context);
int32_t length = _serialize_readInt32(buffer, size);
for (int i = 0; i < length; ++i)
{
JSValue key = _serialize_loadInternal(task, from, buffer, size, depth + 1);
JSValue value = _serialize_loadInternal(task, from, buffer, size, depth + 1);
const char* key_str = JS_ToCString(context, key);
JS_SetPropertyStr(context, error, key_str, value);
JS_FreeCString(context, key_str);
JS_FreeValue(context, key);
}
result = error;
}
break;
case kError:
case kObject:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewObject(context);
for (int i = 0; i < length; ++i)
{
JSValue key = _serialize_loadInternal(task, from, buffer, size, depth + 1);
JSValue value = _serialize_loadInternal(task, from, buffer, size, depth + 1);
const char* key_str = JS_ToCString(context, key);
JS_SetPropertyStr(context, result, key_str, value);
JS_FreeCString(context, key_str);
JS_FreeValue(context, key);
}
}
break;
default:
abort();
break;
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewStringLen(context, *buffer, length);
*buffer += length;
*size -= length;
}
return result;
break;
case kArrayBuffer:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewArrayBufferCopy(context, (const uint8_t*)*buffer, length);
*buffer += length;
*size -= length;
}
break;
case kArray:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewArray(context);
for (int i = 0; i < length; ++i)
{
JS_SetPropertyUint32(context, result, i, _serialize_loadInternal(task, from, buffer, size, depth + 1));
}
}
break;
case kFunction:
{
exportid_t exportId = _serialize_readInt32(buffer, size);
result = tf_task_add_import(task, tf_taskstub_get_id(from), exportId);
}
break;
case kException:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewError(context);
for (int i = 0; i < length; ++i)
{
JSValue key = _serialize_loadInternal(task, from, buffer, size, depth + 1);
JSValue value = _serialize_loadInternal(task, from, buffer, size, depth + 1);
const char* key_str = JS_ToCString(context, key);
JS_SetPropertyStr(context, result, key_str, value);
JS_FreeCString(context, key_str);
JS_FreeValue(context, key);
}
}
break;
case kError:
case kObject:
{
int32_t length = _serialize_readInt32(buffer, size);
result = JS_NewObject(context);
for (int i = 0; i < length; ++i)
{
JSValue key = _serialize_loadInternal(task, from, buffer, size, depth + 1);
JSValue value = _serialize_loadInternal(task, from, buffer, size, depth + 1);
const char* key_str = JS_ToCString(context, key);
JS_SetPropertyStr(context, result, key_str, value);
JS_FreeCString(context, key_str);
JS_FreeValue(context, key);
}
}
break;
default:
abort();
break;
}
return result;
}