swprintf 질문입니다! (segment failure)

chiyo85의 이미지

.
.
.
.

#define _L(x) L ## x
#define _W(x) _L(x)

wchar_t bufw[32];

swprintf(bufw, _W("test_%d_%s"), 1024, _W("string"));

bufw 에는 test_1024_string 가 담겨있어야 하는데
저대로 하면 swprintf부분에서 segment failure 가 나버리네요.

1024부분을 아래와 같이 바꿀 경우
swprintf(bufw, _W("test_1024_%s"), _W("string"));

segment failure는 안나지만 bufw에 달랑 s만 들어가구요....

이것때문에 아주 죽겠습니다 ㅠ 도와주세요오!!! ㅠㅠ

ps. win32에서는 문제없이 잘 돌아갑니다~ 수행환경은 우분투에서 개발툴은 codeblocks를 사용하고 있습니다.

.
.
.
.

오호라의 이미지

> rpm -qa glibc

1. 단순디버그
> gcc -g 옵션을 주고 valgrind 로 돌려본다.

2. 복잡디버그
> glibc 소스를 받아서 -g 옵션으로 컴파일후, /lib or /usr/lib 에 있는 glibc 심볼링크를 교체한후에 valgrind 로 돌려본다. 아니면 LD_LIBRARY_PATH를 변경해서 디버그용 glibc로 붙도록 한다.

3. 소스리뷰
> 해당버젼 glibc 소스를 받아서 본다. 아니면 본인의 소스를 리뷰한다.

Hello World.

chiyo85의 이미지

..

bushi의 이미지

maxlen 과 format 의 위치가 바뀌었습니다.

WPRINTF(3)                 Linux Programmer’s Manual                WPRINTF(3)
 
NAME
       wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf - formatted
       wide-character output conversion
 
SYNOPSIS
...
       int swprintf(wchar_t *wcs, size_t maxlen,
                    const wchar_t *format, ...);
...

...
#define countof(x) (sizeof(x)/sizeof(x[0]))
...
swprintf(bufw, countof(bufw), _W("test_%d_%s"), _W("string"));

추가.

컴파일 때 별다른 경고가 없는 원인을 알봤는데... c99 에서 정의된 함수인 것 같습니다.
-std=c99 로 컴파일 하면 원형과 틀린 argument 에 대해 경고가 출력됨을 확인하실 수 있습니다.

OTL

chiyo85의 이미지

..

오호라의 이미지

> man

Hello World.

chiyo85의 이미지

그럼 woman 입니까

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.