2017-09-06 11 views
0

私は答えを得るためにしばらく検索してきましたが、私はまだ何をすべきかについてはまだ不明です。C:Judy Hashに文字列を挿入して読み取る方法

すべての公式の例では、すべての値とインデックスとそのポインタは、Word_tまたはPWord_t型です。これは、私が知る限り、ある種のintです。私の混乱は、これがchar *またはバッファ(char [])または生の文字列( "string")をどのように参照できるかを理解しようとしています

ここに私が試したことがありますが、あなたはバイナリを印刷するとき)

#include <stdio.h> 
#include <Judy.h> 


int main() 
{ 

     Pvoid_t PJArray = (PWord_t)NULL; // Judy array. 
     PWord_t PValue;     // Judy array element. 
     Word_t Bytes;     // size of JudySL array. 

     JSLI(PValue, PJArray, "WHAT"); 
     *PValue = "HELLO..."; 

     JSLG(PValue, PJArray, "WHAT"); 
     printf("%s\n", &PValue); 

     return 0; 
} 

出力は次のようになります。

`(@�� 
+0

私はここでAPIに精通しておらず、ドキュメントはかなり苦しいですが、 '* PValue =" HELLO ... "で書いているようで、'%s'で読むべきです'' PValue'ではなく '' PValue''です。 – Ryan

答えて

0

私は私のツールを通して、あなたのコードを実行し、それがコードは、バッファオーバーランの問題があります示しています。基本的に、& p値はp値と4バイトのJudySLアレイのアドレスとしてのprintf扱い、それのアドレスをとる

DTS_MSG: Stensal DTS detected a runtime program error. Abort execution! 
DTS_MSG: Reading 1 bytes at 0xbfffdba0 violates type safety. 
DTS_MSG: Diagnostic information: 

- The object to-be-read (start:0xbfffdb9c, size:4 bytes) is allocated at 
-  file:/tmp/a.c::9, 19 
- 0xbfffdb9c    0xbfffdb9f 
- +------------------------+ 
- | the object to-be-read |...... 
- +------------------------+ 
-       ^~~~~~~~~~ 
-  the read starts at 0xbfffdba0 that is right after the object end. 
- Stack trace (most recent call first): 
-[1] file:/src/string/memchr.c::25, 9 
-[2] file:/src/stdio/vfprintf.c::602, 8 
-[3] file:/src/stdio/vfprintf.c::678, 8 
-[4] file:/src/stdio/printf.c::9, 8 
-[5] file:/tmp/a.c::16, 9 
-[6] file:/src/env/__libc_start_main.c::149, 11 

:これはエラーMSGです。あなたは

printf("%s\n", PValue); 

printf("%s\n", &PValue); 

を変更するとそれは私のために、 "P {WHAT" を出力します。私はJudyハッシュに慣れていないので、それが意図した結果であるかどうかを確認する必要があります。

関連する問題