XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/bilibili-API-collect

解决在bv号内的C语言实例线程不安全的问题 (#119)

原示例使用全局变量`char result[13]`, 多线程中同时调用av2bv可能导致结果出错 现改为在堆内存上进行操作以及返回, 由caller来free

27a5968
Executor <exprotected@outlook.com>
提交于

代码差异

1 个文件 +3 -3
Modified other/bvID.md +3 -3
@@ -101,6 +101,7 @@ BV17x411w7KC
101 101
102 102 ```c
103 103 #include <stdio.h>
104 #include <stdlib.h>
104 105 #include <math.h>
105 106 #include <string.h>
106 107
@@ -109,7 +110,6 @@ char tr[124]; //反查码表
109 110 const unsigned long long Xor = 177451812; //固定异或值
110 111 const unsigned long long add = 8728348608; //固定加法值
111 112 const int s[] = {11, 10, 3, 8, 4, 6}; //位置编码表
112 char result[13]; //编码结果
113 113
114 114 //初始化反查码表
115 115 void tr_init()
@@ -130,12 +130,12 @@ unsigned long long bv2av(char bv[])
130 130
131 131 char* av2bv(unsigned long long av)
132 132 {
133 char* result = (char*)malloc(13);
133 134 strcpy(result,"BV1 4 1 7 ");
134 135 av = (av ^ Xor) + add;
135 136 for (int i = 0; i < 6; i++)
136 137 result[s[i]] = table[(unsigned long long)(av / (unsigned long long)pow(58, i)) % 58];
137 char *bv=result;
138 return bv;
138 return result;
139 139 }
140 140
141 141 int main()