| Ticket UUID: | 95e287b956e7b1dd2d03729fe27d38574e4f3d12 | ||
| Title: | uninit value use in stringObj-4.2 | ||
| Type: | Bug | Created on: | 2023-03-06 17:37:34 |
| Submitter: | dgp | Assigned to: | jan.nijtmans |
| Subsystem: | 10. Objects | Severity: | Important |
| Priority: | 5 Medium | Last modified: | 2023-03-08 14:33:17 |
| Status: | Closed | Closed by: | jan.nijtmans |
| Resolution: | Fixed | Closed on: | 2023-03-08 14:33:17 |
| Version: | 8.6 | ||
| Description: | ||||
valgrind run over test stringObj-4.2: ---- stringObj-4.2 start ==27231== Conditional jump or move depends on uninitialised value(s) ==27231== at 0x5A8425: Tcl_UtfToChar16 (tclUtf.c:534) ==27231== by 0x5A8999: Tcl_UtfToChar16DString (tclUtf.c:736) ==27231== by 0x591640: SetUTF16StringFromAny (tclStringObj.c:216) ==27231== by 0x56FB12: Tcl_ConvertToType (tclObj.c:977) ==27231== by 0x429729: TeststringobjCmd (tclTestObj.c:1373) ==27231== by 0x434E1F: Dispatch (tclBasic.c:4997) ==27231== by 0x434EA7: TclNRRunCallbacks (tclBasic.c:5037) ==27231== by 0x434773: Tcl_EvalObjv (tclBasic.c:4756) ==27231== by 0x436DD5: TclEvalEx (tclBasic.c:5913) ==27231== by 0x559F7D: Tcl_FSEvalFileEx (tclIOUtil.c:1782) ==27231== by 0x5669A6: Tcl_MainEx (tclMain.c:405) ==27231== by 0x410188: main (tclAppInit.c:94) ==27231== ==27231== Conditional jump or move depends on uninitialised value(s) ==27231== at 0x5A8439: Tcl_UtfToChar16 (tclUtf.c:548) ==27231== by 0x5A8999: Tcl_UtfToChar16DString (tclUtf.c:736) ==27231== by 0x591640: SetUTF16StringFromAny (tclStringObj.c:216) ==27231== by 0x56FB12: Tcl_ConvertToType (tclObj.c:977) ==27231== by 0x429729: TeststringobjCmd (tclTestObj.c:1373) ==27231== by 0x434E1F: Dispatch (tclBasic.c:4997) ==27231== by 0x434EA7: TclNRRunCallbacks (tclBasic.c:5037) ==27231== by 0x434773: Tcl_EvalObjv (tclBasic.c:4756) ==27231== by 0x436DD5: TclEvalEx (tclBasic.c:5913) ==27231== by 0x559F7D: Tcl_FSEvalFileEx (tclIOUtil.c:1782) ==27231== by 0x5669A6: Tcl_MainEx (tclMain.c:405) ==27231== by 0x410188: main (tclAppInit.c:94) ==27231== ==27231== Conditional jump or move depends on uninitialised value(s) ==27231== at 0x5A8513: Tcl_UtfToChar16 (tclUtf.c:555) ==27231== by 0x5A8999: Tcl_UtfToChar16DString (tclUtf.c:736) ==27231== by 0x591640: SetUTF16StringFromAny (tclStringObj.c:216) ==27231== by 0x56FB12: Tcl_ConvertToType (tclObj.c:977) ==27231== by 0x429729: TeststringobjCmd (tclTestObj.c:1373) ==27231== by 0x434E1F: Dispatch (tclBasic.c:4997) ==27231== by 0x434EA7: TclNRRunCallbacks (tclBasic.c:5037) ==27231== by 0x434773: Tcl_EvalObjv (tclBasic.c:4756) ==27231== by 0x436DD5: TclEvalEx (tclBasic.c:5913) ==27231== by 0x559F7D: Tcl_FSEvalFileEx (tclIOUtil.c:1782) ==27231== by 0x5669A6: Tcl_MainEx (tclMain.c:405) ==27231== by 0x410188: main (tclAppInit.c:94) ==27231== ==27231== Use of uninitialised value of size 8 ==27231== at 0x5A8A8D: Tcl_UtfCharComplete (tclUtf.c:779) ==27231== by 0x5A89DC: Tcl_UtfToChar16DString (tclUtf.c:740) ==27231== by 0x591640: SetUTF16StringFromAny (tclStringObj.c:216) ==27231== by 0x56FB12: Tcl_ConvertToType (tclObj.c:977) ==27231== by 0x429729: TeststringobjCmd (tclTestObj.c:1373) ==27231== by 0x434E1F: Dispatch (tclBasic.c:4997) ==27231== by 0x434EA7: TclNRRunCallbacks (tclBasic.c:5037) ==27231== by 0x434773: Tcl_EvalObjv (tclBasic.c:4756) ==27231== by 0x436DD5: TclEvalEx (tclBasic.c:5913) ==27231== by 0x559F7D: Tcl_FSEvalFileEx (tclIOUtil.c:1782) ==27231== by 0x5669A6: Tcl_MainEx (tclMain.c:405) ==27231== by 0x410188: main (tclAppInit.c:94) ==27231== ==27231== Conditional jump or move depends on uninitialised value(s) ==27231== at 0x5A8425: Tcl_UtfToChar16 (tclUtf.c:534) ==27231== by 0x5A89F3: Tcl_UtfToChar16DString (tclUtf.c:741) ==27231== by 0x591640: SetUTF16StringFromAny (tclStringObj.c:216) ==27231== by 0x56FB12: Tcl_ConvertToType (tclObj.c:977) ==27231== by 0x429729: TeststringobjCmd (tclTestObj.c:1373) ==27231== by 0x434E1F: Dispatch (tclBasic.c:4997) ==27231== by 0x434EA7: TclNRRunCallbacks (tclBasic.c:5037) ==27231== by 0x434773: Tcl_EvalObjv (tclBasic.c:4756) ==27231== by 0x436DD5: TclEvalEx (tclBasic.c:5913) ==27231== by 0x559F7D: Tcl_FSEvalFileEx (tclIOUtil.c:1782) ==27231== by 0x5669A6: Tcl_MainEx (tclMain.c:405) ==27231== by 0x410188: main (tclAppInit.c:94) ==27231== ==27231== Conditional jump or move depends on uninitialised value(s) ==27231== at 0x5A8439: Tcl_UtfToChar16 (tclUtf.c:548) ==27231== by 0x5A89F3: Tcl_UtfToChar16DString (tclUtf.c:741) ==27231== by 0x591640: SetUTF16StringFromAny (tclStringObj.c:216) ==27231== by 0x56FB12: Tcl_ConvertToType (tclObj.c:977) ==27231== by 0x429729: TeststringobjCmd (tclTestObj.c:1373) ==27231== by 0x434E1F: Dispatch (tclBasic.c:4997) ==27231== by 0x434EA7: TclNRRunCallbacks (tclBasic.c:5037) ==27231== by 0x434773: Tcl_EvalObjv (tclBasic.c:4756) ==27231== by 0x436DD5: TclEvalEx (tclBasic.c:5913) ==27231== by 0x559F7D: Tcl_FSEvalFileEx (tclIOUtil.c:1782) ==27231== by 0x5669A6: Tcl_MainEx (tclMain.c:405) ==27231== by 0x410188: main (tclAppInit.c:94) ==27231== ==27231== Conditional jump or move depends on uninitialised value(s) ==27231== at 0x5A8513: Tcl_UtfToChar16 (tclUtf.c:555) ==27231== by 0x5A89F3: Tcl_UtfToChar16DString (tclUtf.c:741) ==27231== by 0x591640: SetUTF16StringFromAny (tclStringObj.c:216) ==27231== by 0x56FB12: Tcl_ConvertToType (tclObj.c:977) ==27231== by 0x429729: TeststringobjCmd (tclTestObj.c:1373) ==27231== by 0x434E1F: Dispatch (tclBasic.c:4997) ==27231== by 0x434EA7: TclNRRunCallbacks (tclBasic.c:5037) ==27231== by 0x434773: Tcl_EvalObjv (tclBasic.c:4756) ==27231== by 0x436DD5: TclEvalEx (tclBasic.c:5913) ==27231== by 0x559F7D: Tcl_FSEvalFileEx (tclIOUtil.c:1782) ==27231== by 0x5669A6: Tcl_MainEx (tclMain.c:405) ==27231== by 0x410188: main (tclAppInit.c:94) ==27231== ++++ stringObj-4.2 PASSED | ||||
| User Comments: | ||||
jan.nijtmans added on 2023-03-06 20:49:43:
Question: Does core-8-6-branch have the same valgrind issue in the stringObj-4.2 testcase? I suspect it does. If so, it needs to be fixed there first. What happens is the following:
teststringobj set 1 abcdef
teststringobj setlength 1 10
So, a string with length 5 is enlarged to length 10. That means that the last 4(!) bytes of the string will be uninitialized. Then: teststringobj length2 1 So, the internal utf-16 representation of the string is generated, and the utf-16 length of the result is determined. That means that we are generating the utf-16 representation of a partly uninitialized string. Not strange that valgrind conplains! Proposed solution: Don't run "teststringobj length2" any more for this testcase, in core-8-6-branch, core-8-branch and in trunk. jan.nijtmans added on 2023-03-06 21:19:13:
Proposed fix [9dd5f7f10d7c6409|here] jan.nijtmans added on 2023-03-07 07:46:06:
Fixed [04077c7b2e3962f5|here] dgp added on 2023-03-08 14:17:10:
Your comments make sense to me. I haven't dug in to seek an explanation, but `make valgrind` on the core-8-6-branch did not report the problem. What do you think of an alternative solution where stringObj-4.2 is not modified, but is constrained so that test is skipped in a valgrind run? I have to imagine that comparing the two paths of computing string lengths was the point of the test, now lost. The existing test iortrans.tf-11.1 is an example of this approach. jan.nijtmans added on 2023-03-08 14:33:17:
> What do you think of an alternative solution where stringObj-4.2 is not modified, but is constrained so that test is skipped in a valgrind run? Yes, I considered that. But ... uninitialized memory can contain anything. If the memory happens to contain a valid multy-byte UTF-8 sequence (e.g. 0xC0 0x80), then "teststringobj length2 1" will return a value < 10 and the test fails. This shows the test is bogus anyway. What could be done is change "teststringobj setlength" such that when the length is increased compared to the previous length, then the memory is filled with something (e.g. all 0-bytes). That would make stringObj-4.2 predictable, and it would also solve this valgrind issue. | ||||
