我一直在試圖理解爲什麼我運行的C語言編寫的languagge程序而得到「段錯誤」。分段故障問題,GDB消息
我試過gdb。
這是我得到的消息:
Program received signal SIGSEGV, Segmentation fault.
0x0016e5e0 in mysql_slave_send_query() from /usr/lib/libmysqlclient.so.16
(gdb) step
Single stepping until exit from function mysql_slave_send_query,
which has no line number information.
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
事實是,我沒有得到任何編譯器錯誤/警告消息,但該程序不能正常工作 正常。
任何人都可以幫助我嗎?
我的查詢是:
char query[512];
sprintf(query, "SELECT t1.Art_Acquisto as 'Cod',t2.Des_Articolo as 'Descrizione',t4.Cod_Categoria as 'Cat.',t1.Data_Acquisto as" "'data',t1.Netto_Acquisto as'Importo',t3.Des_Fornitore as 'Fornitore' from "
"Aquisti as t1, Articoli as t2, Fornitori as t3, Categorie as t4 where t1.Art_Acquisto = t2.Cod_Articolo and "
"t1.fornitoreM = t3.codiceF and t4.codiceC = t2.categoriaA and Art_Acquisto ='%s'order by Data_Acquisto;",Cod_Articolo);
首先,編譯並與'-g'標誌喜歡讓調試符號,並確保崩潰真的用'sprintf'發生。此外,請確保'Cod_Articolo'不是太大以至於它將字符串推過511字節(+ null哨兵)邊界。最後但並非最不重要,'Cod_Articolo'實際上是否指向一個有空的C字符串的有效內存位置? – DarkDust
也有興趣你如何實際調用'mysql_slave_send_query'(或者如果它被另一種方法包裝,你如何調用它)。我的觀點是:是否有可能傳遞了未初始化或錯誤的指針?例如,你通過'query'或'&query'? – DarkDust
你能告訴我們從Cod_Articolo的定義到調用mysql_slave_send_query()的代碼嗎? –