3

我有一个将 uids 转换为用户名的函数,

char *uid2name (uid_t uid)
{
    struct passwd *pwd = getpwuid (uid);
    if (pwd)
        return strdup (pwd->pw_name);

    return NULL;
}

我称之为:

name = uid2name (atoi (blabal));

ABRT有时它会因错误或错误而崩溃BUS

(我知道有符号整数和无符号整数之间存在转换,但我用负值测试了 getpwuid 函数,它不会崩溃。)

Program received signal SIGBUS, Bus error.
[Switching to Thread 1088039264 (LWP 7572)]
0x00007f504afaff10 in malloc_consolidate () from /lib64/tls/libc.so.6
#0  0x00007f504afaff10 in malloc_consolidate () from /lib64/tls/libc.so.6
#1  0x00007f504afb0f17 in _int_malloc () from /lib64/tls/libc.so.6
#2  0x00007f504afb2c52 in malloc () from /lib64/tls/libc.so.6
#3  0x00007f504afa26ba in __fopen_internal () from /lib64/tls/libc.so.6
#4  0x00007f50499ce04a in internal_setent () from /lib64/libnss_files.so.2
#5  0x00007f50499ce5b0 in _nss_files_getpwuid_r ()
   from /lib64/libnss_files.so.2
#6  0x00007f504afd63fd in getpwuid_r@@GLIBC_2.2.5 () from /lib64/tls/libc.so.6
#7  0x00007f504afd5d5d in getpwuid () from /lib64/tls/libc.so.6
#8  0x00007f504b783579 in uid2name (uid=Variable "uid" is not available.
) at XX.c

有什么想法可以在这里出错吗?

4

0 回答 0