3
0
Fork
You've already forked chewing-utils
0

build error on openSUSE OBS: 64-bit portability issue #1

Open
opened 2013年04月24日 13:27:04 +02:00 by marguerite · 4 comments
marguerite commented 2013年04月24日 13:27:04 +02:00 (Migrated from github.com)
Copy link

Hi,

[ 136s] E: libchewing 64bit-portability-issue che.c:1066
[ 136s] E: libchewing 64bit-portability-issue key2pho-utf8.c:98

代码片段:

che.c

void entry_active(GtkWidget obj, gpointer vbox, const char *zhuin)
{
int i, length;
char *chr_zhuin;
GtkWidget *box = vbox;
GtkWidget *bl;
gchar buf[4];
gchar *text = gtk_entry_get_text(GTK_ENTRY(obj));
/

the representation of Mandarin Phonetic Symbols consists of initial,
middle, fnal consonants (each occupies 3 bytes in UTF-8), and tone
(2 bytes in UTF-8). Therefore, we declare 11 bytes in zhuin_buffer.
*/
char zhuin_buffer[3 * 3 + 2 + 1];

length = chewing_utf8_strlen(text);

gtk_container_foreach(GTK_CONTAINER(box), gtk_widget_destroy, NULL);

if (zhuin)
chr_zhuin = strtok(zhuin, " ");
else
chr_zhuin = " ";
for(i = 0; i < length; i++) {
// 下面这行提示有问题
chewing_utf8_strncpy(buf, chewing_utf8_strseek(text, i), 1, 1);
/* try to find the zhuin for the chinese character */
if (zhuin_dictionary && find_zhuin(zhuin_dictionary, buf, zhuin_buffer)) {
chr_zhuin = zhuin_buffer;
} else {
chr_zhuin = " ";
}
bl = che_new_label_button_box(buf, chr_zhuin);
gtk_widget_show_all(GTK_WIDGET(bl));
gtk_box_pack_start_defaults( GTK_BOX(box), GTK_WIDGET (bl));
if (zhuin)
chr_zhuin = strtok(NULL, " ");
}
}

key2pho-utf8.c

int Uint2PhoneUTF8( char *phone, long seq )
{
int i, j, k;
char *pos;
char buffer[5];
for ( i = 0, j = 0; i < 4; i++) {
k = ((seq >> shift[ i ]) & sb[ i ] ) - 1;
// 下面这行提示有问题
if ( k >= 0 && (pos = chewing_utf8_strseek( zhuin_tab[ i ], k )) )
{
chewing_utf8_strncpy(buffer, pos, 1, 1);
strcat(phone, buffer);
j++;
}
}
return j;
}

报错函数定义是:

void*
chewing_utf8_strseek(char src, size_t n)
{
int i = 0;
char *iter = (char
)src;
for( i = 0; i < n; i++ )
{
iter += chewing_utf8_byte2len(iter[0]);
}
return (void*)iter;
}

chewing_utf8_byte2len 定义是

/* Return bytes of a UTF-8 character */
int
chewing_utf8_byte2len(unsigned char b)
{
return utf8len_tab[b];
}

utf8len_tab 定义是:

/* Table of UTF-8 length _/
static char utf8len_tab[256] =
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /bogus/
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /_bogus*/
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1,
};

帮忙看一下,谢谢。

Hi, [ 136s] E: libchewing 64bit-portability-issue che.c:1066 [ 136s] E: libchewing 64bit-portability-issue key2pho-utf8.c:98 代码片段: che.c void entry_active(GtkWidget _obj, gpointer vbox, const char *zhuin) { int i, length; char *chr_zhuin; GtkWidget *box = vbox; GtkWidget *bl; gchar buf[4]; gchar *text = gtk_entry_get_text(GTK_ENTRY(obj)); /_ the representation of Mandarin Phonetic Symbols consists of initial, middle, fnal consonants (each occupies 3 bytes in UTF-8), and tone (2 bytes in UTF-8). Therefore, we declare 11 bytes in zhuin_buffer. */ char zhuin_buffer[3 \* 3 + 2 + 1]; length = chewing_utf8_strlen(text); gtk_container_foreach(GTK_CONTAINER(box), gtk_widget_destroy, NULL); if (zhuin) chr_zhuin = strtok(zhuin, " "); else chr_zhuin = " "; for(i = 0; i < length; i++) { // 下面这行提示有问题 chewing_utf8_strncpy(buf, chewing_utf8_strseek(text, i), 1, 1); /\* try to find the zhuin for the chinese character */ if (zhuin_dictionary && find_zhuin(zhuin_dictionary, buf, zhuin_buffer)) { chr_zhuin = zhuin_buffer; } else { chr_zhuin = " "; } bl = che_new_label_button_box(buf, chr_zhuin); gtk_widget_show_all(GTK_WIDGET(bl)); gtk_box_pack_start_defaults( GTK_BOX(box), GTK_WIDGET (bl)); if (zhuin) chr_zhuin = strtok(NULL, " "); } } key2pho-utf8.c int Uint2PhoneUTF8( char *phone, long seq ) { int i, j, k; char *pos; char buffer[5]; for ( i = 0, j = 0; i < 4; i++) { k = ((seq >> shift[ i ]) & sb[ i ] ) - 1; // 下面这行提示有问题 if ( k >= 0 && (pos = chewing_utf8_strseek( zhuin_tab[ i ], k )) ) { chewing_utf8_strncpy(buffer, pos, 1, 1); strcat(phone, buffer); j++; } } return j; } 报错函数定义是: void* chewing_utf8_strseek(char _src, size_t n) { int i = 0; char *iter = (char_)src; for( i = 0; i < n; i++ ) { iter += chewing_utf8_byte2len(iter[0]); } return (void*)iter; } chewing_utf8_byte2len 定义是 /\* Return bytes of a UTF-8 character */ int chewing_utf8_byte2len(unsigned char b) { return utf8len_tab[b]; } utf8len_tab 定义是: /\* Table of UTF-8 length _/ static char utf8len_tab[256] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /_bogus_/ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /_bogus*/ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1, }; 帮忙看一下,谢谢。
davy-tw commented 2013年04月25日 18:40:06 +02:00 (Migrated from github.com)
Copy link

猜測錯誤點在於
chewing_utf8_strseek(char src, size_t n)
size_t 會根據作業系統的環境而改變長度(32 64 bit)
可是裡面定義的操作卻是
int i = 0;
for( i = 0; i < n; i++ )
{
iter += chewing_utf8_byte2len(iter[0]);
}
用int i 去跟 sizt_t n 做運算處裡可能會有問題
不過裡面固定是 iter[0] 理論上執行並不會出錯?

猜測錯誤點在於 chewing_utf8_strseek(char src, size_t n) size_t 會根據作業系統的環境而改變長度(32 64 bit) 可是裡面定義的操作卻是 int i = 0; for( i = 0; i < n; i++ ) { iter += chewing_utf8_byte2len(iter[0]); } 用int i 去跟 sizt_t n 做運算處裡可能會有問題 不過裡面固定是 iter[0] 理論上執行並不會出錯?
marguerite commented 2013年04月25日 19:32:32 +02:00 (Migrated from github.com)
Copy link

哎呦终于有人回应我了。

本机编译(64bit)是不会报这个错误的,运行也正常。(是代码 weakness,不是用不了)

问题出在 OBS 的策略,就是 RedHat/SuSE 的 RPM 的 brp 代码检查。

在编译服务器上编译完成后会查代码,因为这两个发行版背后的公司和他们本身都被移植到了 arm 或者 ppc 以及 ibm s390...这种小处出错运行时很难排错,所以强制编译时排,不修复的话拒绝生成最终 RPM。

但是,我是 openSUSE 的维护者...编译服务器上编不出包的话,用户就用不了了...

让别人给看了下,他出的补丁也解决不了这个错误

--- hash-editor.orig/src/chewing-utf8-util.h
+++ hash-editor/src/chewing-utf8-util.h
@@ -1,3 +1,4 @@
+typedef signed char int8_t;
#ifndef CHEWING_UTF8_UTIL_H
#define CHEWING_UTF8_UTIL_H

哎呦终于有人回应我了。 本机编译(64bit)是不会报这个错误的,运行也正常。(是代码 weakness,不是用不了) 问题出在 OBS 的策略,就是 RedHat/SuSE 的 RPM 的 brp 代码检查。 在编译服务器上编译完成后会查代码,因为这两个发行版背后的公司和他们本身都被移植到了 arm 或者 ppc 以及 ibm s390...这种小处出错运行时很难排错,所以强制编译时排,不修复的话拒绝生成最终 RPM。 但是,我是 openSUSE 的维护者...编译服务器上编不出包的话,用户就用不了了... 让别人给看了下,他出的补丁也解决不了这个错误 --- hash-editor.orig/src/chewing-utf8-util.h +++ hash-editor/src/chewing-utf8-util.h @@ -1,3 +1,4 @@ +typedef signed char int8_t; #ifndef CHEWING_UTF8_UTIL_H #define CHEWING_UTF8_UTIL_H
marguerite commented 2013年04月25日 19:34:51 +02:00 (Migrated from github.com)
Copy link

哦对了,他的原话是这样的:

char* 指针在 64 位下是 64 位

哦对了,他的原话是这样的: char\* 指针在 64 位下是 64 位
yuyichao commented 2013年04月26日 01:18:47 +02:00 (Migrated from github.com)
Copy link

@marguerite 单修这个错误一行就行, 不过代码里面相关的不相关的问题实在太多了, 于是一起修了.... 这个错误不修的话在x86_64上运行没有段错误那是运气好, 在大端64位上面运行要是没出错那绝对是机器坏了.

.... 总之手动打patch的话在这里
github.com/yuyichao/chewing-utils@c0c20c54bd.patch

@marguerite 单修这个错误一行就行, 不过代码里面相关的不相关的问题实在太多了, 于是一起修了.... 这个错误不修的话在x86_64上运行没有段错误那是运气好, 在大端64位上面运行要是没出错那绝对是机器坏了. .... 总之手动打patch的话在这里 https://github.com/yuyichao/chewing-utils/commit/c0c20c54bda47ccb6a8fb370169b187e05a37d59.patch
Commenting is not possible because the repository is archived.
No Branch/Tag specified
master
No results found.
Labels
Clear labels
bug
duplicate
enhancement
invalid
question
wontfix
arch
aarch64
系統架構是 Aarch64
arch
x86_64
系統架構是 x86_64
cannot reproduce
無法重現問題 Cannot reproduce the issue
contribution welcome
歡迎來幫忙 Contributions are very welcome, get started here
duplicate
重複的問題回報 This issue or pull request already exists
good first issue
適合新手 Interested in contributing? Get started here.
help wanted
需要高手相助 Need some help
invalid
回報的問題無效 Something is wrong
kind
bug
有東西不正常運作 Something is not working
kind
doc
加強文件說明 Enhance documentation
kind
enhancement
新功能 New feature
kind
mega issue
同一個問題回報中包含多個問題 Multiple issues reported
kind
question
只是問問題 Asking a question
needinfo
需要更多資訊 More information is needed
os
apple
作業系統是 MacOS 或 iOS
os
linux
作業系統是 GNU Linux
os
windows
作業系統是 Windows
to be determined
還未被說服有需求 Can't decide whether this is needed
upstream
跟上游軟體相關 Related to an upstream repository, already reported there
wontfix
我們決定不處理 Won't be fixed
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chewing/chewing-utils#1
Reference in a new issue
chewing/chewing-utils
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?