vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, I found the problem in snprintf on linux (maybe another unix) boxes in info.c (CVS HEAD). The problematic part is something like: buf = "text"; snprintf(buf,size,"%s append",buf); buf = "text append" on Windows (MS VC compiler) buf = " append" on linux (gcc compiler) I solve it this way (main idea): snprintf(buf + strlen(buf), " append"); There are more parameters (char *, int, ...) in real usage. More details is here: http://pgfoundry.org/tracker/index.p...125 &atid=538 The patch is created againist CVS. Comments are welcome Luf ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| |||
| > I solve it this way (main idea): > snprintf(buf + strlen(buf), " append"); Ugh typo mistake: snprintf(buf + strlen(buf), sizeof(buf), " append"); My hands are faster than my head :-( There is buffer overrun erron becouse I have to decrease sizeof(buf) with strlen(buf). So I attach second try of this patch againist CVS HEAD. Comments are welcome Luf ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly |
| |||
| Ludek Finstrle wrote: > Hello, > > I found the problem in snprintf on linux (maybe another unix) boxes > in info.c (CVS HEAD). The problematic part is something like: > > buf = "text"; > snprintf(buf,size,"%s append",buf); > > buf = "text append" on Windows (MS VC compiler) > buf = " append" on linux (gcc compiler) > > I solve it this way (main idea): > snprintf(buf + strlen(buf), " append"); Hmm bad news. If so, it may be better to use the sequence like the following for example. char *query_ptr; size_t bufsize_res; int slen; /* Initialize */ query_ptr = columns_query; bufsize_res = sizeof(columns_query); if (..) { if ((slen = snprintf(query_ptr, bufsize_res, .., )) <= 0) { .. error_handling .. } query_ptr += slen; bufsize_res -= slen; } ... regards, Hiroshi Inoue ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
| |||
| > > buf = "text"; > > snprintf(buf,size,"%s append",buf); > > > > buf = "text append" on Windows (MS VC compiler) > > buf = " append" on linux (gcc compiler) > > > > I solve it this way (main idea): > > snprintf(buf + strlen(buf), " append"); > > Hmm bad news. > If so, it may be better to use the sequence like the following for example. > > char *query_ptr; > size_t bufsize_res; > int slen; > > /* Initialize */ > query_ptr = columns_query; > bufsize_res = sizeof(columns_query); > > if (..) > { > if ((slen = snprintf(query_ptr, bufsize_res, .., )) <= 0) > { > .. error_handling .. > } > query_ptr += slen; > bufsize_res -= slen; > } > > ... I'm not sure. There are a lot of strcat, my_strcat, schema_strcat calls between snprintf. There is only one place where snprintf could be called after another snprintf. BTW it's something what snprintf_addlen is doing. Or am I miss something? I do the patch with minimal changes in mind. In my opinion strcat may be faster in joining more char *. Regards, Luf ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| |||
| > > > buf = "text"; > > > snprintf(buf,size,"%s append",buf); > > > > > > buf = "text append" on Windows (MS VC compiler) > > > buf = " append" on linux (gcc compiler) > > > > > > I solve it this way (main idea): > > > snprintf(buf + strlen(buf), " append"); > > > > Hmm bad news. > > If so, it may be better to use the sequence like the following for example. > > > > char *query_ptr; > > size_t bufsize_res; > > int slen; > > > > /* Initialize */ > > query_ptr = columns_query; > > bufsize_res = sizeof(columns_query); > > > > if (..) > > { > > if ((slen = snprintf(query_ptr, bufsize_res, .., )) <= 0) > > { > > .. error_handling .. > > } > > query_ptr += slen; > > bufsize_res -= slen; > > } > > > > ... > > I'm not sure. There are a lot of strcat, my_strcat, schema_strcat calls > between snprintf. There is only one place where snprintf could be called > after another snprintf. I change the snprintf_addlen to snprintf_len as you mentioned. Third try of patch attached. Comments are welcome Luf ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |
| |||
| > I change the snprintf_addlen to snprintf_len as you mentioned. > > Third try of patch attached. I forgot attach the patch. Luf ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |
| |||
| Fri, Jun 09, 2006 at 02:13:23PM +0200, Ludek Finstrle napsal(a): > > > > buf = "text"; > > > > snprintf(buf,size,"%s append",buf); > > > > > > > > buf = "text append" on Windows (MS VC compiler) > > > > buf = " append" on linux (gcc compiler) > > > > > > > > I solve it this way (main idea): > > > > snprintf(buf + strlen(buf), " append"); > > > > > > Hmm bad news. > > > If so, it may be better to use the sequence like the following for example. > > > > > > char *query_ptr; > > > size_t bufsize_res; > > > int slen; > > > > > > /* Initialize */ > > > query_ptr = columns_query; > > > bufsize_res = sizeof(columns_query); > > > > > > if (..) > > > { > > > if ((slen = snprintf(query_ptr, bufsize_res, .., )) <= 0) > > > { > > > .. error_handling .. > > > } > > > query_ptr += slen; > > > bufsize_res -= slen; > > > } > > > > > > ... > > > > I'm not sure. There are a lot of strcat, my_strcat, schema_strcat calls > > between snprintf. There is only one place where snprintf could be called > > after another snprintf. > > I change the snprintf_addlen to snprintf_len as you mentioned. I take a look at all snprintf in psqlodbc an I find one more place where it's problematic. If we accept snprintf_add I change one call to it. Additional patch attached, comments are welcome Luf ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| |||
| > > > > buf = "text"; > > > > snprintf(buf,size,"%s append",buf); > > > > > > > > buf = "text append" on Windows (MS VC compiler) > > > > buf = " append" on linux (gcc compiler) > > > > > > > > I solve it this way (main idea): > > > > snprintf(buf + strlen(buf), " append"); > > > > > > Hmm bad news. > > > If so, it may be better to use the sequence like the following for example. > > > > > > char *query_ptr; > > > size_t bufsize_res; > > > int slen; > > > > > > /* Initialize */ > > > query_ptr = columns_query; > > > bufsize_res = sizeof(columns_query); > > > > > > if (..) > > > { > > > if ((slen = snprintf(query_ptr, bufsize_res, .., )) <= 0) > > > { > > > .. error_handling .. > > > } > > > query_ptr += slen; > > > bufsize_res -= slen; > > > } > > > > > > ... > > > > I'm not sure. There are a lot of strcat, my_strcat, schema_strcat calls > > between snprintf. There is only one place where snprintf could be called > > after another snprintf. > > I change the snprintf_addlen to snprintf_len as you mentioned. > > Third try of patch attached. I make patch againist CVS after yours huge commit. What's your opinion? Could we fix linux bug? Or do you prefer ifdef or what's your idea about change these lines: snprintf(buf,bufsize,"%s adding 1",buf); strcat(buf," adding 2"); snprintf(buf,bufsize,"%s adding 3",buf); I think it's hard to maintain code you mentioned above. This calls are only in catalog information (relatively short query - used not so often). Patch attached contains previous psqlodbc_snprintf_3try and psqlodbc_snprintf_next. Regards, Luf ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
| |||
| Ludek Finstrle wrote: > > I make patch againist CVS after yours huge commit. What's your opinion? > Is the second parameter of snprintf_add needed ? Aren't the parameter values always strlen(the first parameter) ? Is snprintf_len needed instead of snprintf ? Though the current code ignores snprintf errors, it's simply my negligence.. regards, Hiroshi Inoue ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |
| ||||
| Tue, Jun 13, 2006 at 11:12:58PM +0900, Hiroshi Inoue wrote: > Ludek Finstrle wrote: > > > > I make patch againist CVS after yours huge commit. What's your opinion? > > > > Is the second parameter of snprintf_add needed ? > Aren't the parameter values always strlen(the first parameter) ? You're right. I think more about it and "add" means add to the end so I changed the patch as you pointed. > Is snprintf_len needed instead of snprintf ? > Though the current code ignores snprintf errors, it's simply > my negligence.. I'm voting for keeping safer snprintf_len. But I can change it if you wish. New patch attached. Regards, Luf ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match |
| Thread Tools | |
| Display Modes | |
|
|