Changeset 85567 in vbox
- Timestamp:
- Jul 30, 2020 5:21:27 PM (5 years ago)
- Location:
- trunk/src/VBox/GuestHost/SharedClipboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp
r84717 r85567 129 129 /** @todo Add Wayland / Weston support. */ 130 130 #endif 131 /** @todo r=aeichner The "LAST" in there was causing tstClipboardGH-X11.cpp:XInternAtom to crash because it was reading out side of the array. */132 { NULL, SHCLX11FMT_INVALID, VBOX_SHCL_FMT_NONE },133 131 }; 134 132 … … 185 183 186 184 185 #ifdef TESTCASE 186 /** 187 * Return the max. number of elements in the X11 format table. 188 * Used by the testing code in tstClipboardGH-X11.cpp 189 * which cannot use RT_ELEMENTS(g_aFormats) directly. 190 * 191 * @return size_t The number of elements in the g_aFormats array. 192 */ 193 SHCL_X11_DECL(size_t) clipReportMaxX11Formats(void) 194 { 195 return (RT_ELEMENTS(g_aFormats)); 196 } 197 #endif 198 187 199 /** 188 200 * Returns the atom corresponding to a supported X11 format. … … 195 207 { 196 208 LogFlowFunc(("format=%u -> pcszAtom=%s\n", uFmtIdx, g_aFormats[uFmtIdx].pcszAtom)); 197 AssertReturn(uFmtIdx < =RT_ELEMENTS(g_aFormats), 0);209 AssertReturn(uFmtIdx < RT_ELEMENTS(g_aFormats), 0); 198 210 return clipGetAtom(pCtx, g_aFormats[uFmtIdx].pcszAtom); 199 211 } … … 207 219 SHCL_X11_DECL(SHCLX11FMT) clipRealFormatForX11Format(SHCLX11FMTIDX uFmtIdx) 208 220 { 209 AssertReturn(uFmtIdx < =RT_ELEMENTS(g_aFormats), SHCLX11FMT_INVALID);221 AssertReturn(uFmtIdx < RT_ELEMENTS(g_aFormats), SHCLX11FMT_INVALID); 210 222 return g_aFormats[uFmtIdx].enmFmtX11; 211 223 } … … 219 231 static SHCLFORMAT clipVBoxFormatForX11Format(SHCLX11FMTIDX uFmtIdx) 220 232 { 221 AssertReturn(uFmtIdx < =RT_ELEMENTS(g_aFormats), VBOX_SHCL_FMT_NONE);233 AssertReturn(uFmtIdx < RT_ELEMENTS(g_aFormats), VBOX_SHCL_FMT_NONE); 222 234 return g_aFormats[uFmtIdx].uFmtVBox; 223 235 } … … 729 741 for (i = 0; i < *pcLen; ++i) 730 742 { 731 for (j = 0; j < RT_ELEMENTS(g_aFormats) - 1; ++j) /** @todo r=aeichner Don't include the last invalid format. */743 for (j = 0; j < RT_ELEMENTS(g_aFormats); ++j) 732 744 { 733 745 Atom target = XInternAtom(XtDisplay(widget), … … 2346 2358 return rc; 2347 2359 } 2348 -
trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11.cpp
r82922 r85567 41 41 extern SHCLX11FMT clipRealFormatForX11Format(SHCLX11FMTIDX uFmtIdx); 42 42 extern Atom clipGetAtom(PSHCLX11CTX pCtx, const char *pcszName); 43 extern size_t clipReportMaxX11Formats(void); 43 44 44 45 … … 187 188 Atom atom = 0; 188 189 unsigned i = 0; 189 while (g_aFormats[i].pcszAtom) 190 const size_t j = clipReportMaxX11Formats(); 191 192 for (i = 0; i < j; ++i) 190 193 { 191 194 if (!strcmp(pcsz, g_aFormats[i].pcszAtom)) 192 195 atom = (Atom) (i + 0x1000); 193 ++i;194 196 } 195 197 for (i = 0; i < RT_ELEMENTS(g_tst_apszSupAtoms); ++i) … … 366 368 { 367 369 unsigned index = atom - 0x1000; 370 AssertReturn(index < clipReportMaxX11Formats(), NULL); 368 371 pcszName = g_aFormats[index].pcszAtom; 369 372 } … … 420 423 static SHCLX11FMTIDX tstClipFindX11FormatByAtomText(const char *pcszAtom) 421 424 { 422 unsigned i = 0; 423 while (g_aFormats[i].pcszAtom) 425 const size_t j = clipReportMaxX11Formats(); 426 427 for (unsigned i = 0; i < j; ++i) 424 428 { 425 429 if (!strcmp(g_aFormats[i].pcszAtom, pcszAtom)) 426 430 return i; 427 ++i;428 431 } 429 432 return NIL_CLIPX11FORMAT;
Note:
See TracChangeset
for help on using the changeset viewer.