将数据从SVGimage格式转换为xmlDocPtr共振峰的函数出错

将数据从SVGimage格式转换为xmlDocPtr共振峰的函数出错,c,C,我正在从事一个小型的网络开发项目。 前端:Javascript Jquery HTML 后端:Node.js+C 该项目包括创建、验证、添加形状、设置属性(等)SVG文件的功能,并在Firefox web浏览器中显示文件(该项目应在Linux操作系统上运行) 所有处理SVG文件的函数都是用C开发的,并使用ffi napi模块调用Node.js中的函数。 在开发时,我在将数据从SVGimage格式转换为xmlDocPtr格式的函数中出错 C代码错误位置附在下面: “错误:字符串不在UTF-8中”

我正在从事一个小型的网络开发项目。 前端:Javascript Jquery HTML 后端:Node.js+C

该项目包括创建、验证、添加形状、设置属性(等)SVG文件的功能,并在Firefox web浏览器中显示文件(该项目应在Linux操作系统上运行)

所有处理SVG文件的函数都是用C开发的,并使用ffi napi模块调用Node.js中的函数。 在开发时,我在将数据从SVGimage格式转换为xmlDocPtr格式的函数中出错

C代码错误位置附在下面:

“错误:字符串不在UTF-8中”

使用Win 10操作系统在chrome上运行此项目时,我没有任何错误: 但是在Linux操作系统(Centos 7)上部署此项目时,我遇到了这个错误。 我正在寻求帮助解决这个问题

if (image->rectangles) {
    iter = createIterator(image->rectangles);
    Rectangle* rect = NULL;
    while ((rect = nextElement(&iter)) != NULL)
    {
        node = xmlNewChild(root_node, NULL, BAD_CAST "rect", NULL);
        sprintf(buf, "%.2f%s", rect->x, rect->units);
        xmlNewProp(node, BAD_CAST "x", BAD_CAST buf);
        sprintf(buf, "%.2f%s", rect->y, rect->units);
        xmlNewProp(node, BAD_CAST "y", BAD_CAST buf);
        sprintf(buf, "%.2f%s", rect->width, rect->units);
        xmlNewProp(node, BAD_CAST "width", BAD_CAST buf);
        sprintf(buf, "%.2f%s", rect->height, rect->units);
        xmlNewProp(node, BAD_CAST "height", BAD_CAST buf);
        
        if (!addAttributesToNode(node, rect->otherAttributes)) {
            fail = true;
            break;
        }
    }
}
bool addAttributesToNode(xmlNodePtr node, List* attributes)
{
    if (node == NULL || attributes == NULL)
        return false;

    ListIterator iter = createIterator(attributes);
    Attribute* attr = NULL;
    while ((attr = nextElement(&iter)) != NULL)
    {
        if (attr->name == NULL)
            return false;
        xmlNewProp(node, BAD_CAST attr->name, BAD_CAST attr->value);
    }

    return true;
}