Tout ane sa a, nou te monte atravè plaj yo nan kòd louvri, envestire krimen, retire kwasans, ak kolekte trofe yo. Jodi a, nou te deside antre nan salòn la pi pousyè: yon sherif ki gen eksperyans pentire sou bar la ak rele sou dè santèn de bugs ki pi asirans ak ki pi enpòtan nan West la Wild. Eske ou vle yon istwa enteresan? Pou tout ane sa a, nou te batay divès kalite bugs soti nan C ak C++ pwojè sous louvri. Nou te pran chak moun, interrogated li, ak anrejistre malaks li yo nan dosye a. Koulye a, li se tan yo rele ka yo pi notè. Jodi a, mwen pral di ou yon istwa sou 10 ki pi enteresan bugs nou te jwenn nan diferan wòch yo nan Wild West la. Pou chak nan fragman sa yo, nou gen yon dosye separe - yon atik konplè. Epi pou ki pi dedye, nou te chwazi 5 atik ki pi popilè sou C ak C++ pwojè pibliye ane sa a: Ki jan itilizasyon frivol nan distribitè polymorfik ka imite lavi ou C++ pwogramè gid nan konpòtman undefined Istwa nan C ak C++. Pandan dezyèm: estanda nan C ak C++, Qt, Clang, ak Unreal Engine std::array nan C++ se pi vit pase array nan C. Pafwa Safe array manipilasyon? Pa janm te konnen sou li Ou ka jwenn lis la konplè nan atik soti nan blog nou an sou sit entènèt nou an nan lyen la. Lyen Sit, vwayajè, istwa a pral yon long N10 Yon fwa, nou te gen yon ka sou yon chèz manke. Mèz la te toujou nan estati, men chak fwa nou te vle monte nan vil la, li te parèt disparèt nan lè ti. PvS-Study a avèti nan: Yon literal '0.5f' nan kalite a 'float' se implikabman cast nan kalite a 'unsigned char' pandan y ap rele fonksyon an 'SetRenderColor'. 168 V674 nan Pwodwi pou Telefòn_Bugbait.cpp typedef unsigned char byte; inline void CBaseEntity::SetRenderColor( byte r, byte g, byte b, byte a ) { m_clrRender.Init( r, g, b, a ); } void CGrenadeBugBait::BugBaitTouch( CBaseEntity *pOther ) { .... if ( pSporeExplosion ) { .... pSporeExplosion->SetRenderColor( 0.0f, 0.5f, 0.25f, 0.15f ); // <= .... } .... } nan fonksyon mete nan valè koulè, kote chak paramèt se nan tip ak yon varyete valè posib nan Si ou ap eseye pase arguments nan tip, pati fraksyonèl la pral truncated. Se poutèt sa, nan nan nan fonksyon paramèt yo pral gen valè menm jan ak . SetRenderColor RGBA unsigned char [0 .. 255] float r g b a 0 Malgre ke depo a manke enfòmasyon blame, se konsa mwen gen de senaryo sou ki jan erè sa a te parèt nan kòd la. Yon fwa fonksyon an te pwosesis koulè nan yon reprezantan pwen flòt. pwosesis la te pita chanje nan nèt, men pa tout sit apèl te ajou. Devlopè a erè te kwè ke SetRenderColor te travay ak nimewo pwen flòt ak mete yo dapre. Isit la se alantou: V674 literal '0.5f' nan 'float' kalite a se implikabman cast nan 'unsigned char' kalite pandan y ap rele fonksyon an 'SetRenderColor'. Inspekte dezyèm argument. weapon_bugbait.cpp 171 V674 Literal '25.6' nan 'double' kalite a se implikabman cast nan 'int' kalite pandan y ap rele fonksyon an 'SetScrollRate'. Inspèti premye argument. grenade_tripmine.cpp 179 Nou detekte bug sa a nan pwojè a Source SDK. Ou ka jwenn atik la konplè nan lyen la. Lyen N9 Yon fwa nou te gen yo kouri yon sèn nan menm fason atravè prairie a. Li te pase ke nou te chanje sou yon sèl nou te deja kouri. Se sèlman sa a fwa, li te mennen nan yon kote konplètman diferan. The PVS-Studio warning: Pou itilize nan 'si (A) {...} elatriye si (A) {...}' modèl te detekte. Gen yon probabilite nan prezans erè logik. Liy Tcheke: 2903, 3053. V517 nan li_bif_info.z 2903 BIF_RETTYPE system_info_1(BIF_ALIST_1) { .... if (is_tuple(BIF_ARG_1)) { // L2778 .... } else if (BIF_ARG_1 == am_scheduler_id) { // L2782 .... } .... else if (BIF_ARG_1 == am_garbage_collection) { // L2903 .... } else if (BIF_ARG_1 == am_fullsweep_after) { // L2921 .... } else if (BIF_ARG_1 == am_garbage_collection) { // L3053 .... } else if (BIF_ARG_1 == am_instruction_counts) { // L3056 .... } .... else if (ERTS_IS_ATOM_STR("halt_flush_timeout", BIF_ARG_1)) { // L3552 .... } } Analizè a te detekte plizyè jaden ak tchèk identik nan yon fonksyon ki gen yon kantite gwo de Deklarasyon - Sepandan, chak nan yo gen yon logik diferan: ak Dapre kantite jaden yo ak jaden an 150-linè ant duplikat yo, li pa sove ke sa a ka rive. Analiz estatik ede anpeche ka sa yo. if-else if prèske 800 liy Premye tcheke Tcheke nan dezyèm Nou detekte bug sa a nan pwojè a Erlang; ou ka jwenn atik la konplè nan lyen la. Lyen N8 Mwen te konnen yon Sherif ki te gen sèlman yon sentans pou tout krim yo: "Pa gen okenn blesi." Li te yon strange. PvS-Study a avèti nan: " Lè sa a" deklarasyon an se ekivalan ak fragman kòd la pita. Vwayaje cmComputeLinkInformation.cxx 1748 bool cmComputeLinkInformation::CheckImplicitDirItem(LinkEntry const& entry) { BT<std::string> const& item = entry.Item; // We only switch to a pathless item if the link type may be // enforced. Fortunately only platforms that support link types // seem to have magic per-architecture implicit link directories. if (!this->LinkTypeEnabled) { return false; } // Check if this item is in an implicit link directory. std::string dir = cmSystemTools::GetFilenamePath(item.Value); if (!cm::contains(this->ImplicitLinkDirs, dir)) { // Only libraries in implicit link directories are converted to // pathless items. return false; } // Only apply the policy below if the library file is one that can // be found by the linker. std::string file = cmSystemTools::GetFilenameName(item.Value); if (!this->ExtractAnyLibraryName.find(file)) { return false; } return false; } Analizè a sanble ke gen definitivman yon bagay ki mal nan fonksyon : CheckImplicitDirItem Lè sa a, branch la nan dènye a si deklarasyon an duplique kòd la anba a (retour false;); chak branch nan ekzekisyon fonksyon an fini ak false return; when called from , it'll never trigger an early return; AddFullItem konplè fonksyon kò ka ranplase ak retou false;, kòm sa a pa pral chanje pwogram konpòtman an. Remake ke fonksyon an se ekri lè l sèvi avèk " Yon modèl ki ede diminye nòt kòd: rezilta a ki pi pozitif se mete nan fen a nan fonksyon an, ak restan nan kòd la - nan ka divèrjan de nan objektif la nan fonksyon an - ta dwe sispann fonksyon an kòm byen vit ke posib. Premye Retounen Nan egzanp nou an, nou ka asume ke rezilta ki pi "pozitif" nan fonksyon an se ke yon objè nan type has passed all the necessary checks with a Retour nan valè. LinkEntry true Isit la se yon opsyon ki jan yo fikse kòd la: .... std::string file = cmSystemTools::GetFilenameName(item.Value); if (!this->ExtractAnyLibraryName.find(file)) { return false; } return true; We detected this bug in the CMake project; you can find the full article at the . Lyen Lyen N7 Once in a village, I saw a desperate player who bet all his gold on the card that wasn't even in the deck. The judge just threw up his hands, and the gold remained lying on the table. The PVS-Studio warning: Dereferencing nan iteratè a invalid 'shades.end()' ka rive. Vye granmoun ColorHelper.cpp 194 nan winrt::Windows::UI::Color ColorHelper::GetAccentColor( const winrt::Windows::UI::Color& color ) { .... auto shades = std::map<float, HSL>(); .... // 3f is quite nice if the whole non-client area is painted constexpr auto readability = 1.75f; for (auto shade : shades) { if (shade.first >= readability) { return HslToRgb(shade.second); } } return HslToRgb(shades.end()->second); // <= } Èske li posib ke pa gen anyen nan koulè yo pral satisfè kritè yo lisibilite? Nou pa ka di an sekirite, men li se byen posib. Sa a se yon nan -pa bezwen flash nenpòt papye psikolojik yo pwouve li, depi deferencing fè sa eksactman, kòm iteratè sa a montre jis pase eleman an dènye nan yon . Textbook ka undefined behavior std::map::end() std::map Nou detekte bug sa a nan pwojè a Windows Terminal; ou ka jwenn atik la plen nan lyen an. Lyen N6 Yon fwa mwen te fè yon komès ak yon lòt vwayajè yo pataje yon trezò nou te jwenn. Li koute, vwayaje, epi li te disparèt tankou yon mirage. Pa gen moun te wè l 'soti. The PVS-Studio warning: referans 'graf' vin invalide lè pousantaj entelijan retounen pa yon fonksyon se detwi. Vwayaje utils.cpp 391 template<typename T> struct Ptr : public std::shared_ptr<T>; // .... Ptr<FlannNeighborhoodGraph> FlannNeighborhoodGraph::create( const Mat &points, int points_size, int k_nearest_neighbors_, bool get_distances, int flann_search_params_, int num_kd_trees) { return makePtr<FlannNeighborhoodGraphImpl>(points, points_size, k_nearest_neighbors_, get_distances, flann_search_params_, num_kd_trees); } void Utils::densitySort (const Mat &points, int knn, Mat &sorted_points, std::vector<int> &sorted_mask) { // .... // get neighbors FlannNeighborhoodGraph &graph = // <= *FlannNeighborhoodGraph::create(points, points_size, knn, true /*get distances */, 6, 1); std::vector<double> sum_knn_distances (points_size, 0); for (int p = 0; p < points_size; p++) { const std::vector<double> &dists = graph.getNeighborsDistances(p); for (int k = 0; k < knn; k++) sum_knn_distances[p] += dists[k]; } // .... } Yon ti kras plis konte sou Ptr template<typename T> struct Ptr : public std::shared_ptr<T> { inline Ptr(const std::shared_ptr<T>& o) CV_NOEXCEPT : std::shared_ptr<T>(o) {} inline Ptr(std::shared_ptr<T>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} typename std::add_lvalue_reference<T>::type operator*() const CV_NOEXCEPT { return *std::shared_ptr<T>::get(); } // .... } template<typename _Tp, typename ... A1> static inline Ptr<_Tp> makePtr(const A1&... a1) { static_assert( !has_custom_delete<_Tp>::value, "Can't use this makePtr with custom DefaultDeleter"); return (Ptr<_Tp>)std::make_shared<_Tp>(a1...); } Sèvi ak pousantaj entelijan pa rezoud pwoblèm nan referans twou san danje ak aksè memwa isit la. Antre nan sa a. Sa a se ki jan kòd la travay. Kreye fonksyon an kreye ak retounen yon pousantaj entelijan nan kalite a FlannNeighborhoodGraphImpl, ak kantite referans objè li yo se youn. The reference is created for the value of this smart pointer while the object reference count remains unchanged. graph Kòm pousantaj la se yon objè tanperati, kontè a referans pral rive nan null apre initialization se fè, rele objè a jere. Koulye a, referans la peze nan yon objè destriksyon. Referans pou loop se yon referans invalide. Kòm yon rezilta, kòd la ki te parèt ki kòrèkteman mennen nan comportement undefined. Anplis de sa, PVS-Studio se pa sèlman zouti a ki detekte pwoblèm sa a; sanitizer a fè sa a tou. Isit la se . Pwoteksyon To fix this, we need to save the smart pointer so that the objè rete jiska fen nan blòk la. Pou egzanp, nou ka fè : FlannNeighborhoodGraph Kòm sa a std::vector<double> sum_knn_distances (points_size, 0); { // get neighbors auto graph = FlannNeighborhoodGraph::create(points, points_size, knn, true /*get distances */, 6, 1); for (int p = 0; p < points_size; p++) { const std::vector<double> &dists = graph->getNeighborsDistances(p); for (int k = 0; k < knn; k++) sum_knn_distances[p] += dists[k]; } } We also limited the opsyon pou libere resous la apre egzèsis la nan loop la. graph Nou detekte bug sa a nan pwojè a OpenCV; ou ka jwenn atik la konplè nan . Lyen N5 Yon fwa, yon ekspè lokal te desen yon kat nan yon koreksyon rivyè, men li te kouri soti nan kabòn. Se konsa, seksyon an ki pi enpòtan, ki te desen ak pati ki sot pase yo nan kabòn, te lave soti ak plon an premye. Sa a se kote tout moun te kontinye disparèt. PvS-Studio nan avèti: Konsidere tcheke ekspresyon an '1 << (brake->type + 1)'. Bit chanje nan valè a 32-bit ak yon ekstansyon pita nan kalite a 64-bit. V629 nan Pwodwi pou Telefòn: phpdbg_bp.c 1209 Gwosè nan mas la bit se mwens pase gwosè a nan operand an premye. Sa a pral lakòz pèdi nan bits ki pi wo. Vye granmoun Pwodwi pou Telefòn: phpdbg_bp.c 1209 uint64_t flags .... PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num) { .... if ((brake = phpdbg_find_breakbase_ex(num, &table, &numkey, &strkey))) { int type = brake->type; char *name = NULL; size_t name_len = 0L; switch (type) { .... default: { if (zend_hash_num_elements(table) == 1) { PHPDBG_G(flags) &= ~(1<<(brake->type+1)); // <= } } } .... } } Math guys, no time to relax. The Varyab se nan kalite, pandan y ap is of the Kòd la fèt yo retire yon bit espesifik soti nan . Now, let's take a closer look at what's really going on: flags unsigned long int brake->type int flags The constant of the type is shifted left by a certain number of bits. Most often, the type is of 32 bits. We hope that the shift isn't by 32 or more bits, otherwise we get . 1 int int undefined behavior The result of the shift is bitwise inverted. The result of the inversion still has the type. int Rezilta a nan enversion an se ekspanse nan yon 64-bit ki pa te sigare kalite a paske nan operand la kòrèk. Pandan ke kalite a orijinal la se sigare, extension signe pral rive. Sa vle di ke pou nimewo pozitif, 32 bits ki pi enpòtan yo pral gen nòt bits, ak pou nimewo negatif, yo pral gen yo. Bitwise "AND" apwopriye rezilta a konvèsyon nan flags. Pèt nan bits enpòtan nan flags pral rive lè operand a dwat se pozitif. Li pral sèlman rive lè gen yon chanjman 31 bits nan bò solèy - lè 31 bits nan flags gen yo dwe netwaye. Jwenn yon dokiman. Remake ki jan anpil nou bezwen kenbe nan tèt ou pou yon ekspresyon ki san danje? Problèm la se nan diferan gwosè operand ak siy nan kèk sous-expressions. Pou rezoud li, devlopè yo jis bezwen chanje kalite a nan constant from nan , ak kòd la pral kouri kòm sa ki fèt: 1 int unsigned long long PHPDBG_G(flags) &= ~( 1uLL <<(brake->type+1)); Nou te dekouvri bug sa a nan pwojè a PHP; ou ka jwenn atik la konplè nan . Lyen N4 Yon fwa mwen te wè yon ti cowboy jere yon outlaw. Li kouvri l 'nan yon fen mouri nan youn nan bar yo lokal, men li te tire pa sou kriminèl la, men sou pwòp refleksyon li nan yon miray pousyè, kouvri li nan ti kras. PvS-Study a avèti nan: The assignment operator should be protected from the case of 'this == &other'. V794 nan fs_pat.cpp nan 36 FsPath& FsPath::operator=(FsPath&& other) { m_path = std::move(other.m_path); other.m_path.clear(); return *this; } Nan snippet sa a, nou gen operatè a deplase atribisyon pou klas, ki transfere done soti nan lòt objè a nan instans la kounye a. Sepandan, pa gen okenn tcheke pou self-attribution ki ka mennen nan konsekans ki pa planifye. FsPath (this == &other) Si yon eseye se fè pou atribye objè a nan tèt li, operasyon deplase kontni nan nan , ak apèl ki sot pase a nan clears the data. As a result, finalman nan yon estati inattend, epi yo ka sèlman vle devlopè kontan debugging :) m_path = std::move(other.m_path); other.m_path m_path other.m_path.clear(); m_path Pou elimine risk la, nou rekòmande ajoute tcheke a anba a nan kòmansman an nan operatè a: if (this == std::addressof(other)) { return *this; } Sèvi instead of the operatè asire konpare adrès ki kòrèk menm lè operatè a Li se overloaded nan klas la. std::addressof & & We detected this bug in the Nau Engine project; you can find the full article at the . link Lyen N3 I once saw a shaman trying to summon a spirit without reaching the sacred grounds. A spirit came, but it was a completely different one—a coyote from the nearest ravine. PvS-Study a avèti nan: sing the 'window_id' function of uninitialized derived class while initializing the 'modal_dialog' base class will lead to undefined behavior. 29 V1099 install_dependencies.hpp nan class install_dependencies : public modal_dialog { public: explicit install_dependencies(const addons_list& addons) : modal_dialog(window_id()), addons_(addons) // <= {} .... private: virtual const std::string& window_id() const override; .... } Thanks to this code snippet, I can tell you more about undefined behavior. As we can see above, the Klas la se soti nan class. In the konstriktè, klas la baz se inisyalize ak valè a retounen pa (attend pou li...) non-static la fonksyon. Se konsa, sa a pral rive: install_dependencies modal_dialog install_dependencies window_id Execution of the initialization list: a call to the method; install_dependencies::window_id a constructor call to the class; modal_dialog an initialization of the data member; addons_ Execution of the constructor body of the class. install_dependencies Li rezilta nan yon apèl fonksyon nan yon objè klas ki pa te deja inisyalize! Sa a vire ki anba a : rule of the standard Member functions (including virtual member functions, [class.virtual]) can be called for an object under construction Similarly, an object under construction can be the operand of the typeid operator ([expr.typeid]) or of a dynamic_cast ([expr.dynamic.cast]). However, if these operations are performed in a ctor-initializer (or in a function called directly or indirectly from a ctor-initializer) before all the mem-initializers for base classes have completed, the program has undefined behavior. Men, tanpri, gen plis! Kòm ou ka wè, member function is virtual and overridden in the Problèm ka rive pita lè yon pwogramè ekri yon klas derive nan ki Li se ekselan. window_id install_dependencies window_id Si yon objè nan klas sa a derive se kreye ak konstriktè a se ekzekite, pa gen okenn enfòmasyon sou egzistans an nan nouvo override a. Se konsa, function will always be called in the initialization list. This may differ from the developers' original intention. You can read more about it . installed_dependencies installed_dependencies::window_id isit la We detected this bug in the Wesnoth project; you can find the full article at the . link link N2 Mwen te konnen yon cowboy ki te tire nan yon omwen sou miray la, mistwore li pou yon lannwit la. Shot la boumed, gips la kraze, kite sèlman yon koupe nan miray la. Objektif la pa janm te egziste, ak reparasyon an te pran anpil travay. The PVS-Studio warning: Pousantaj null se pase nan 'fseek' fonksyon. Tcheke argiman an premye. V575 Pwodwi pou Pwodwi pou Pwoteksyon void ati_eeprom_load_mach8(ati_eeprom_t *eeprom, char *fn, int mca) { FILE *fp; .... fp = nvr_fopen(eeprom->fn, "rb"); size = 128; if (!fp) { if (mca) { (void) fseek(fp, 2L, SEEK_SET); // <= memset(eeprom->data + 2, 0xff, size - 2); fp = nvr_fopen(eeprom->fn, "wb"); fwrite(eeprom->data, 1, size, fp); .... } Nou bezwen chaje done ki estoke nan NVRAM nan adaptè videyo a, ki nou kenbe nan yon dosye binè. Si dosye a pa egziste, nou bezwen kreye li ak "default" done. Eseye gade nan ka a kote dosye a manke. Nou chanje pousan dosye a, men li se null. Kòm yon rezilta, nou jwenn yon null pointer dereference. fp Jwenn yon gade pi byen nan nan estanda pa definye kondisyon pou fonksyon an premye paramèt ak pa garanti yon tcheke pou . Sa vle di li depann sou devlopè bibliyotèk estanda yo sèvi ak li byen. Koulye a, akeyi: fseek C11 nan NULL nan GNU glibc; BSD libc soti nan FreeBSD 14.3; Microsoft Universal CRT soti nan Windows SDK 10.0.26100; Vwayaje nan v1.2.5. The last two C standard library implementations are here as guests: 86Box is not designed to work with them, or their compatibility hasn't been checked. The Se konsa, tanpri kòmanse ak livrezon estanda espere ak mande yo repete aksyon yo menm ak yon null pwen dosye. build instructions Flicking the power switch Nou pran yon IBM PS/2 modèl 55SX soti nan plato a imajinal ak "plug" akseleratè a IBM 8514 / A 2D ki te fè pa ATI. nan Premye tèm tès se yon instans Windows bati lè l sèvi avèk MinGW. Nou asire ke dosye a NVRAM se absans anvan kòmanse - nou tcheke directory for the . file. If it is there, we delete it. %userprofile%\86Box VMs\<virtual machine name>\nvr ati8514_mca.nvr nan Turning on the power supply, and... Pa gen anyen eksplode! Tout se ok: dosye a NVRAM se ekri, òdinatè a kouri, ak tès fòm sou glibc se konplè. Pa gen okenn defè detekte. Kòmanse nan FreeBSD. Libraries libc implemente estanda C libraries nan OS sa a. Sa a se jeneralman valab pou tout sistèm opere BSD-family. We use the same configuration. We check for the absence of the NVRAM dosye nan path. Three, two, one, power is on... ati8514_mca.nvr ~/.local/share/86Box/Virtual Machines/<virtual machine name>/nvr Well, only an event from dènye pase ta ka pi byen dekri situa sa a :) Ben Grubbs nan nan Apre ouvèti ogyon nou an, squeezed fèmen apre eksplozyon an, nou gade nan konsole a: nou te konfime yon rezilta anormal! void VMManagerSystem::launchMainProcess() Full Command: "/root/86Box/build_freebsd/src/86Box" ("--vmpath", "/root/.local/share/86Box/Virtual Machines/somevm", "--vmname", "somevm") Connection received on 86Box.socket.5876c5 Connection disconnected Abnormal program termination while launching main process: exit code 11, exit status QProcess::CrashExit Yon dosye demode koutim te parèt alantou emulatè a kouri. Dekwa pou akeyi LLDB: root@freebsd:~/86Box/build_freebsd/src # lldb 86Box -c 86Box.core (lldb) target create "86Box" --core "86Box.core" Core file '/root/86Box/build_freebsd/src/86Box.core' (x86_64) was loaded. (lldb) bt * thread #1, name = '86Box', stop reason = signal SIGSEGV * frame #0: 0x0000000832f880bf libc.so.7`_flockfile(fp=0x0000000000000000) at _flock_stub.c:65:20 frame #1: 0x0000000832f8b675 libc.so.7`fseek(fp=0x0000000000000000, offset=2, whence=0) at fseek.c:62:2 frame #2: 0x00000000018cd964 86Box`ati_eeprom_load_mach8(eeprom=...., fn=<unavailable>, mca=1) at vid_ati_eeprom.c:61:20 nan null pointer fè yon spectacular fire show - pa gen okenn fason yo bloke dosye a paske descriptor li se invalide. Malgre ke, LLDB pa vle travay nan tan reyèl, tou de ak yon ti kras or with a loud boom and special effects. Therefore, I can't show you how the code is executed like in Windows. fp lost connection We detected this bug in the 86Box project; you can find the full article at the . link link N1 A sheriff I know from a neighboring town once wrote in an interrogation transcript that a witness had confirmed his own testimony. The court never figured out if it was a mistake or a clever defense tactic. The PVS-Studio warning: Gen egzanp sous-expressions nan bò a ak bò a nan '==' operatè a: PeekArg.getValNo() == PeekArg.getValNo() V501 nan Pwodwi pou Telefòn Pwodwi pou Telefòn Pwodwi pou Telefòn SDValue PPCTargetLowering::LowerCall_AIX(....) const { .... for (unsigned I = 0, E = ArgLocs.size(); I != E;) { .... CCValAssign &GPR1 = VA; .... if (I != E) { // If only 1 GPR was available, there will only be one custom GPR and // the argument will also pass in memory. CCValAssign &PeekArg = ArgLocs[I]; if (PeekArg.isRegLoc() && PeekArg.getValNo() == PeekArg.getValNo()) // <= { assert(PeekArg.needsCustom() && "A second custom GPR is expected."); CCValAssign &GPR2 = ArgLocs[I++]; RegsToPass.push_back(std::make_pair(GPR2.getLocReg(), DAG.getZExtOrTrunc(ArgAsInt, dl, MVT::i32))); } } .... } Nou asume pou kounye a ke li se yon lòt victim nan kopi pastè. Nou tcheke si Nenpòt efè segondè: getValNo class CCValAssign{ .... unsigned ValNo; unsigned getValNo() const { return ValNo; } } Pa gen anyen etonan isit la, sepandan. Al gade nan dènye a : commit CCValAssign &GPR1 = VA; .... assert(I != E && "A second custom GPR is expected!"); CCValAssign &GPR2 = ArgLocs[I++]; assert(GPR2.isRegLoc() && GPR2.getValNo() == GPR1.getValNo() && GPR2.needsCustom() && "A second custom GPR is expected!"); RegsToPass.push_back( std::make_pair(GPR2.getLocReg(), DAG.getZExtOrTrunc(ArgAsInt, dl, MVT::i32))); Ide a se klè: yon ka eksepsyonèl ki te anvan pwoteje pa yon afirman te redesigned nan yon branch regilye. Tèks la komite tou montre sa a. Sa a patch aplike bò a apèl nan plasman fonksyon apèl argiman nan memwa stack. Sa a retire limitasyon a kounye a kote LLVM sou AIX will report fatal error when arguments can't be contained in registers. Remake ke, nan adisyon a erè a jwenn, gen yon lòt atansyon enteresan: CCValAssign &PeekArg = ArgLocs[I]; .... CCValAssign &GPR2 = ArgLocs[I++]; // here PeekArg == GPR2 Devlopè a ka entansyon ekri yon bagay tankou sa a: if (I != E) { CCValAssign &GPR2 = ArgLocs[I]; if (GPR2.isRegLoc() && PeekArg.getValNo() == GPR1.getValNo()) { assert(PeekArg.needsCustom() && "A second custom GPR is expected."); I++; RegsToPass.push_back(std::make_pair( GPR2.getLocReg(), DAG.getZExtOrTrunc(ArgAsInt, dl, MVT::i32))); } } Men, pou klarifikasyon, devlopè yo te rive soti from to show that, unlike the previous unconditional code, the argument now needs to be "peeked" first. And during the copy-paste process, Li te aksidan rale soti nan kondisyon an. PeekArg GPR2 GPR1 Yon koreksyon Li ta dwe: if if (PeekArg.isRegLoc() && PeekArg.getValNo() == GPR1.getValNo()) Interestingly, before migrating to GitHub, LLVM had a code review platform, and the commit included a Isit la, nou ka wè ke revizyon manyen pa toujou ka sove sitiyasyon an: link nan Nou te jwenn bug sa a nan pwojè a LLVM, atik la konplè ki disponib nan lyen la. link Konklisyon Silans te pran sou salòn la, ki te fèmen sèlman pa kranpon an nan pòt la antre ak kranpon an nan chanm la. Dwa bug ki pi enpòtan nan 2025 se kounye a jis istwa pase soti nan jenerasyon nan jenerasyon. Nan sa a Wild West, ou pa ka ale byen lwen san yon patnè serye, se konsa asistans mwen konfyans nan tout ka te analyzer. It's ready to help you find dangerous code snippets: PvS-Study pou pwojè sous louvri; Pou objektif edikasyon; using a for a glorious beginning. 30-day trial version E si wout ou mennen ou nan lòt teritwa, mwen sijere koute istwa sou bugs soti nan pwojè ekri nan Java ak C#. Top 10 erè nan Java nan 2025; Top 10 erè jwenn nan C # pwojè nan 2025.