This document describes rules for diagnosing potentially unsafe code constructions from the perspective of 64-bit programs. It defines key concepts like data types, type sizes, and operations. It then outlines 14 specific rules to check code for issues like implicit conversions between types, virtual functions with mismatched arguments, pointer conversions, and more. The goals are to help developers port applications to 64-bit platforms by identifying code that could cause incorrect behavior. These rules are implemented in the Viva64 static code analysis tool.
Development of a static code analyzer for detecting errors of porting program...PVS-Studio
The article concerns the task of developing a program tool called static analyzer. The tool being developed is used for diagnosing potentially unsafe syntactic structures of C++ from the viewpoint of porting program code on 64-bit systems. Here we focus not on the problems of porting occurring in programs, but on the peculiarities of creating a specialized code analyzer. The analyzer is intended for working with the code of C/C++ programs.
Comparison of analyzers' diagnostic possibilities at checking 64-bit codePVS-Studio
The article compares a specialized static analyzer Viva64 with universal static analyzers Parasoft C++Test and Gimpel Software PC-Lint. The comparison is carried within the framework of the task of porting 32-bit C/C++ code on 64-bit systems or developing new code with taking into account peculiarities of 64-bit architecture.
The article will help the readers understand what size_t and ptrdiff_t types are, what they are used for and when they must be used. The article will be interesting for those developers who begin creation of 64-bit applications where use of size_t and ptrdiff_t types provides high performance, possibility to operate large data sizes and portability between different platforms.
20 issues of porting C++ code on the 64-bit platformAndrey Karpov
Program errors occurring while porting C++ code from 32-bit platforms on 64-bit ones are observed. Examples of the incorrect code and the ways to correct it are given. Methods and means of the code analysis which allow to diagnose the errors discussed, are listed.
This article contains various examples of 64-bit errors. However, we have learnt much more examples and types of errors since we started writing the article and they were not included into it. Please see the article "A Collection of Examples of 64-bit Errors in Real Programs" that covers defects in 64-bit programs we know of most thoroughly. We also recommend you to study the course "Lessons on development of 64-bit C/C++ applications" where we describe the methodology of creating correct 64-bit code and searching for all types of defects using the Viva64 code analyzer.
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...Andrey Karpov
Program errors occurring while porting C++ code from 32-bit platforms on 64-bit ones are observed. Examples of the incorrect code and the ways to correct it are given. Methods and means of the code analysis which allow to diagnose the errors discussed, are listed.
Semantic scaffolds for pseudocode to-code generation (2020)Minhazul Arefin
They propose a method for program generation based on semantic scaffolds, lightweight structures representing the high-level semantic and syntactic composition of a program. By first searching over plausible scaffolds then using these as constraints for a beam search over programs, we achieve better coverage of the search space when compared with existing
techniques. We apply our hierarchical search method to the SPoC dataset for pseudocodeto- code generation, in which we are given line-level natural language pseudocode annotations
and aim to produce a program satisfying execution-based test cases. By using semantic scaffolds during inference, we achieve a 10% absolute improvement in top-100 accuracy
over the previous state-of-the-art. Additionally, we require only 11 candidates to reach the top-3000 performance of the previous best approach when tested against unseen problems, demonstrating a substantial improvement in efficiency.
Development of a static code analyzer for detecting errors of porting program...PVS-Studio
The article concerns the task of developing a program tool called static analyzer. The tool being developed is used for diagnosing potentially unsafe syntactic structures of C++ from the viewpoint of porting program code on 64-bit systems. Here we focus not on the problems of porting occurring in programs, but on the peculiarities of creating a specialized code analyzer. The analyzer is intended for working with the code of C/C++ programs.
Comparison of analyzers' diagnostic possibilities at checking 64-bit codePVS-Studio
The article compares a specialized static analyzer Viva64 with universal static analyzers Parasoft C++Test and Gimpel Software PC-Lint. The comparison is carried within the framework of the task of porting 32-bit C/C++ code on 64-bit systems or developing new code with taking into account peculiarities of 64-bit architecture.
The article will help the readers understand what size_t and ptrdiff_t types are, what they are used for and when they must be used. The article will be interesting for those developers who begin creation of 64-bit applications where use of size_t and ptrdiff_t types provides high performance, possibility to operate large data sizes and portability between different platforms.
20 issues of porting C++ code on the 64-bit platformAndrey Karpov
Program errors occurring while porting C++ code from 32-bit platforms on 64-bit ones are observed. Examples of the incorrect code and the ways to correct it are given. Methods and means of the code analysis which allow to diagnose the errors discussed, are listed.
This article contains various examples of 64-bit errors. However, we have learnt much more examples and types of errors since we started writing the article and they were not included into it. Please see the article "A Collection of Examples of 64-bit Errors in Real Programs" that covers defects in 64-bit programs we know of most thoroughly. We also recommend you to study the course "Lessons on development of 64-bit C/C++ applications" where we describe the methodology of creating correct 64-bit code and searching for all types of defects using the Viva64 code analyzer.
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...Andrey Karpov
Program errors occurring while porting C++ code from 32-bit platforms on 64-bit ones are observed. Examples of the incorrect code and the ways to correct it are given. Methods and means of the code analysis which allow to diagnose the errors discussed, are listed.
Semantic scaffolds for pseudocode to-code generation (2020)Minhazul Arefin
They propose a method for program generation based on semantic scaffolds, lightweight structures representing the high-level semantic and syntactic composition of a program. By first searching over plausible scaffolds then using these as constraints for a beam search over programs, we achieve better coverage of the search space when compared with existing
techniques. We apply our hierarchical search method to the SPoC dataset for pseudocodeto- code generation, in which we are given line-level natural language pseudocode annotations
and aim to produce a program satisfying execution-based test cases. By using semantic scaffolds during inference, we achieve a 10% absolute improvement in top-100 accuracy
over the previous state-of-the-art. Additionally, we require only 11 candidates to reach the top-3000 performance of the previous best approach when tested against unseen problems, demonstrating a substantial improvement in efficiency.
Undefined behavior is closer than you thinkAndrey Karpov
Some people think that undefined behavior is caused only by gross errors (accessing outside the bounds of the array, for instance) or inadequate constructions (i = i++ + ++i, for example). That's why it is quite surprising when a programmer sees undefined behavior in the code that used to work correctly, without arousing any suspicion. One should never let his guard down, programming in C/C++. Because hell is closer than you may think.
Duplicate Code Detection using Control StatementsEditor IJCATR
Code clone detection is an important area of research as reusability is a key factor in software evolution. Duplicate code degrades the design and structure of software and software qualities like readability, changeability, maintainability. Code clone increases the maintenance cost as incorrect changes in copied code may lead to more errors. In this paper we address structural code similarity detection and propose new methods to detect structural clones using structure of control statements. By structure we mean order of control statements used in the source code. We have considered two orders of control structures: (i) Sequence of control statements as it appears (ii) Execution flow of control statements.
Правила статического анализа кода для диагностики потенциально опасных констр...Sergey Vasilyev
В статье сформулированы правила диагностики потенциально опасных синтаксических конструкций в исходном коде программ на языке Си++. Описаны принципы построения статического анализатора исходного кода, реализующего проверку указанных правил.
Презентация посвящена вопросам использования параллельных алгоритмов для создания современных эффективных программных решений. Актуальность данной тематики обусловлена снижением темпов роста тактовой частоты микропроцессоров и возрастанием внимания к использованию всех возможностей многоядерных и многопроцессорных систем. В работе рассмотрен ряд базовых параллельных алгоритмов, таких как умножение матриц, параллельная сортировка Бэтчера, метод Гаусса решения систем линейных алгебраических уравнений и так далее. Приведена реализация этих алгоритмов c использованием языка программирования Си++.
Расчет минимального времени выполнения задач при оптимальном распределении на...Sergey Vasilyev
В презентации кратко рассмотрены методы расчета минимального времени выполнения задач при оптимальном распределении нагрузки между процессорами. Приведенные методы могут применяться для однородных и неоднородных вычислительных систем.
The resource finding system is mainly divided into two parts. First part is the facility for HR people to maintain the projects project timeline (i.e. HR’s can add/delete a project and mark a project completed/failed) which will help in the accuracy calculation of the employee’s. Second part of the project is the data mining part, the HR will enter the required skills for upcoming project then the system will use the employee’s skill sets and accuracy (based on previous projects) to apply apriori algorithm.
Undefined behavior is closer than you thinkAndrey Karpov
Some people think that undefined behavior is caused only by gross errors (accessing outside the bounds of the array, for instance) or inadequate constructions (i = i++ + ++i, for example). That's why it is quite surprising when a programmer sees undefined behavior in the code that used to work correctly, without arousing any suspicion. One should never let his guard down, programming in C/C++. Because hell is closer than you may think.
Duplicate Code Detection using Control StatementsEditor IJCATR
Code clone detection is an important area of research as reusability is a key factor in software evolution. Duplicate code degrades the design and structure of software and software qualities like readability, changeability, maintainability. Code clone increases the maintenance cost as incorrect changes in copied code may lead to more errors. In this paper we address structural code similarity detection and propose new methods to detect structural clones using structure of control statements. By structure we mean order of control statements used in the source code. We have considered two orders of control structures: (i) Sequence of control statements as it appears (ii) Execution flow of control statements.
Правила статического анализа кода для диагностики потенциально опасных констр...Sergey Vasilyev
В статье сформулированы правила диагностики потенциально опасных синтаксических конструкций в исходном коде программ на языке Си++. Описаны принципы построения статического анализатора исходного кода, реализующего проверку указанных правил.
Презентация посвящена вопросам использования параллельных алгоритмов для создания современных эффективных программных решений. Актуальность данной тематики обусловлена снижением темпов роста тактовой частоты микропроцессоров и возрастанием внимания к использованию всех возможностей многоядерных и многопроцессорных систем. В работе рассмотрен ряд базовых параллельных алгоритмов, таких как умножение матриц, параллельная сортировка Бэтчера, метод Гаусса решения систем линейных алгебраических уравнений и так далее. Приведена реализация этих алгоритмов c использованием языка программирования Си++.
Расчет минимального времени выполнения задач при оптимальном распределении на...Sergey Vasilyev
В презентации кратко рассмотрены методы расчета минимального времени выполнения задач при оптимальном распределении нагрузки между процессорами. Приведенные методы могут применяться для однородных и неоднородных вычислительных систем.
The resource finding system is mainly divided into two parts. First part is the facility for HR people to maintain the projects project timeline (i.e. HR’s can add/delete a project and mark a project completed/failed) which will help in the accuracy calculation of the employee’s. Second part of the project is the data mining part, the HR will enter the required skills for upcoming project then the system will use the employee’s skill sets and accuracy (based on previous projects) to apply apriori algorithm.
Static code analysis for verification of the 64-bit applicationsPVS-Studio
The coming of 64-bit processors to the PC market causes a problem which the developers have to solve: the old 32-bit applications should be ported to the new platform. After such code migration an application may behave incorrectly. The article is elucidating question of development and appliance of static code analyzer for checking out of the correctness of such application. Some problems emerging in applications after recompiling in 64-bit systems are considered in this article as well as the rules according to which the code check up is performed.
20 issues of porting C++ code on the 64-bit platformPVS-Studio
Program errors occurring while porting C++ code from 32-bit platforms on 64-bit ones are observed. Examples of the incorrect code and the ways to correct it are given. Methods and means of the code analysis which allow to diagnose the errors discussed, are listed.
Lesson 19. Pattern 11. Serialization and data interchangePVS-Studio
Succession to existing data interchange protocols is an important component of the process of porting a program solution to a new platform. You need to provide the capability of reading the existing projects' formats, data interchange between 32-bit and 64-bit processes, etc.
The forgotten problems of 64-bit programs developmentPVS-Studio
Though the history of 64-bit systems development makes more than a decade, the appearance of 64-bit version of OS Windows raised new problems in the sphere of development and testing applications. In the article there are considered some mistakes connected with 64-bit C/C++ code development to OS Windows. The reasons are explained according to which these mistakes didn't find their reflection in the articles devoted to the migration tasks and are unsatisfactorily detected by the majority of static analyzers.
A Collection of Examples of 64-bit Errors in Real ProgramsAndrey Karpov
This article is the most complete collection of examples of 64-bit errors in the C and C++ languages. The article is intended for Windows-application developers who use Visual C++, however, it will be useful for other programmers as well.
A Collection of Examples of 64-bit Errors in Real ProgramsPVS-Studio
This article is the most complete collection of examples of 64-bit errors in the C and C++ languages. The article is intended for Windows-application developers who use Visual C++, however, it will be useful for other programmers as well.
When porting a 32-bit program to a 64-bit platform, you may encounter changes in its logic related to the use of overloaded functions. If a function is overlapped for 32-bit and 64-bit values, the access to it with an argument of a memsize-type will be translated into different calls on different systems.
64-bit computers have been around and well for a long time already. Most applications have 64-bit versions that can benefit from larger memory capacity and improved performance thanks to the architectural capabilities of 64-bit processors. Developing 64-bit application in C/C++ requires much attention from a programmer. There is a number of reasons for 32-bit code to fail to work properly when recompiled for the 64-bit platform. There are a lot of articles on this subject, so we will focus on some other thing. Let's find out if the new features introduced in C++11 have made 64-bit software programmers' life any better and easier.
Note. The article was originally published in Software Developer's Journal (April 25, 2014) and is published here by the editors' permission.
Lesson 26. Optimization of 64-bit programsPVS-Studio
When a program is compiled in the 64-bit mode, it starts consuming more memory than its 32-bit version. This increase often stays unnoticed, but sometimes memory consumption may grow twice. The growth of memory consumption is determined by the following factors:
• larger memory amounts to store some objects, for example pointers;
• changes of the rules of data alignment in structures;
• growth of stack memory consumption.
Questions concerned with the release of drivers for 64-bit versions of Windows are considered in this article. Some typical problems and the ways of their solutions are listed in the article as well as tools which simplify the process of drivers developing.
Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called "Data Structure". The choice of a particular data model depends on two considerations:
It must be rich enough in structure to reflect the actual relationships of the data in the real world.
The structure should be simple enough that one can effectively process the data when necessary.
Data Structure Operations
The particular data structure that one chooses for a given situation depends largely on the nature of specific operations to be performed.
The following are the four major operations associated with any data structure:
i. Traversing : Accessing each record exactly once so that certain items in the record may be processed.
ii. Searching : Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.
iii. Inserting : Adding a new record to the structure.
iv. Deleting : Removing a record from the structure.
Primitive and Composite Data Types
Primitive Data Types are Basic data types of any language. In most computers these are native to the machine's hardware.
Some Primitive data types are:
Integer
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
The Art of the Pitch: WordPress Relationships and Sales
The static code analysis rules for diagnosing potentially unsafe constructions from the viewpoint of 64-bit programs
1. 1
The static code analysis rules for diagnosing
potentially unsafe constructions from the
viewpoint of 64-bit programs
Evgeniy Ryzhkov, October, 2008
2. 2
Abstract
The article formulates the rules of diagnosing potentially unsafe syntactic constructions in source code of C++
programs and describes the principles of building a static source code analyzer implementing support of the
mentioned rules.
Introduction
The task of the static source code analysis has been known for a long time [1] and there are traditional methods of
solving it both in theory and in practice.
However, progress of the industrial software development sets new tasks before the developers of static code
analyzers. We speak about porting the code of applications on 64-bit platforms, support of parallel programming and
so on. There are many peculiarities and problems [2, 3] in these tasks which many programmers already face. Various
tools and methods can help you diagnose them [4].
This article considers one of the approaches to diagnosing problems in the code of 64-bit applications, exactly –
development of a specialized static code analyzer.
3. 3
A static code analyzer consists of two parts:
The front end compiler – a unit providing parsing and lexical and syntactical analysis of the source code and
building of the parse tree for further analysis;
A set of rules of diagnosing potentially unsafe constructions.
By potentially unsafe constructions we understand such constructions in programs’ code which can cause incorrect
operation of the programs while porting an application on a 64-bit platform. You shouldn’t confuse them with defects
[5] in programs’ code which are errors and must be corrected anyway. Unlike defects potentially unsafe constructions
which are diagnosed by the static code analyzer, must be looked through by a programmer. And it is the programmer
who decides if this code should be considered incorrect in a particular situation. If the programmer considers the
code incorrect, it must be corrected.
Thus, the task of a static code analyzer is to diagnose potentially unsafe constructions with the help of a set of rules.
4. 4
Analysis unit development
The principles of building a static code analyzer are well studied and reviewed in literature [6]. That’s why you should
choose a traditional approach to building the analysis unit to implement an analyzer intended for development of 64-
bit applications.
As the code analyzer being developed is intended for C and C++ languages, we should proceed from what we know
about these programming languages’ type when constructing the analysis unit.
C++ is defined by context-free grammar (classification by Homskiy). To parse C++ programs a syntactic analyzer
recognizing context-free grammar is used. But lexical parsing is implemented on the basis of regular grammar. The
necessity of both lexical and syntactical analyses is explained by the peculiarities of the rules being checked.
Parsing of C++ is implemented by the recursive descendant method (recursive descendant analysis) with return. This
recognition is implemented in the code analysis library VivaCore [7].
The result of the code parse is a derivation tree. In comparison to an abstract syntax tree the derivation tree contains
more information which is sometimes necessary for further analysis. After that a special algorithm traverses the tree
and checks concrete rules.
5. 5
Data types
Before we speak about some rules of diagnosing potentially unsafe constructions we need to decide upon the
architecture we will work out rules for. What is of most importance for us is such a part of an architecture as the data
model. A data model [2] is correlation of the basic data types’ sizes on a particular architecture. Thus, the data model
on the 64-bit Windows version is called LLP64. In the 64-bit Linux LP64 is used. All the rules will be given further for
LLP64 architecture but they can be applied to LP64 too after you replace definitions of the basic types.
Let’s introduce T set – a set of all basic and derived integer types of C++, including pointers. Examples: int, bool, short
int, size_t, viod*, pointers to classes.
Let’s introduce S set – a set of sizes of these types (in bytes), so that Tt Ss . Examples: 1, 2, 4, 8, 16, 32, 64.
The number of members in T and S sets is different – there are more members in T than in S .
Let’s introduce match operation 32 where C++ type is represented within the framework of the 32-bit architecture in
the size of this type: SsSt 32 , and also operation 64 where the language’s type is represented within the
framework of the 64-bit architecture in the size of this type: SsSt 64 . Formally these operations look as follows:
ST :32 and ST :64 .
6. 6
Let’s introduce Tset – a set of all memsize-types (types of variable size) of C++, TT . Examples: size_t, ptrdiff_t,
int*, void*.
Members of Tset have the same property as
Tt :
SsSt
SsSt
*
64
32
, *
ss .
In other words, memsize-types are StStTtTT 6432:, .
Let’s introduce TT 32 set – all the data types which are 32-bit both in 32-bit and 64-bit architectures, that is
StStTtTT 64323232323232 :, . An example: int.
By analogy let’s introduce TT 64 set – all the data types which are 64-bit both in 32-bit and 64-bit architectures. An
example: long long.
7. 7
Sizes of all memsize-types on a 32-bit architecture equal one number q =4 (4 bytes):
SpTt , it is true that qSt 64 . Sizes of all memsize-types on a 64-bit architecture equal number *
q =8 (8
bytes).
Let’s introduce P set – data types "pointers" in C++ language, TP .
Let’s introduce the indirection operation *
in the following way:
TP :*
.
This operation is intended for getting a data type pointed to by the pointer: tp *
. An example: intint* *
.
Let’s introduce D set consisting of all the types derived from double type. An example: double, long double.
8. 8
Rules of code correctness analysis
All the rules of code correctness analysis are presented in the form of functions which receive some arguments
(different for different rules) and return true in case of incorrect code and false if the code is correct. All the rules are
comprised on the results of study and processing of errors of porting code on 64-bit platforms [2].
Conversion of 32-bit integer types to memsize-types
You should consider unsafe constructions of explicit and implicit conversion of 32-bit integer types to memsize-types.
Examples:
unsigned a, c;
size_t b = a;
array[c] = 1;
.otherwise
,if
),( 2321
211
false
TtTttrue
ttF
9. 9
Conversion of memsize-types to 32-bit integer types
You should consider unsafe constructions of explicit and implicit conversion of memsize-types to 32-bit integer types.
An example:
size_t a;
unsigned b = a;
.otherwise
,if
),( 3221
212
false
TtTttrue
ttF
10. 10
Memsize-types in virtual functions
You should consider unsafe a virtual function which satisfies these conditions:
a). The function is defined in a basic class and in the derived class.
b). Types of the functions’ arguments don’t coincide but are equivalent on a 32-bit system (for example: unsigned,
size_t) and non-equivalent on a 64-bit one.
11. 11
An example:
class Base {
virtual void foo(size_t);
};
class Derive : public Base {
virtual void foo(unsigned);
};
Let’s consider tuples 1M and 2M which are sets of members from T set. You should consider unsafe the situation
when 1M and 2M tuples coincide in 32-bit mode and differ in 64-bit mode.
.otherwise
,..1,)()()()(
)()()()(if
),(
642641322321
642641322321
213
false
niSmSmSmSm
SmSmSmSmtrue
MMF
iiii
iiii
12. 12
Memsize-types in overloaded functions
You should consider unsafe call of overloaded functions with the argument of memsize-type. Functions must be
overloaded for 32-bit and 64-bit integer data types.
An example:
void WriteValue(__int32);
void WriteValue(__int64);
...
ptrdiff_t value;
WriteValue(value);
13. 13
Let’s consider call of a function with n actual arguments. If we have 2 or more overloaded functions with the same
number of arguments, we need to perform the following check.
A - the tuple of types of the function’s actual parameters;
1A - the tuple of types of the first overloaded function’s formal parameters;
2A - the tuple of types of the second overloaded function’s formal parameters;
.otherwise
,..1,)()()()()(if
),,( 641322642321
214
false
niTaTaTaTaTatrue
AAAF iiiii
14. 14
Conversion of pointers’ types
You should consider unsafe explicit conversion of one type of a pointer to another if one of them points to a 32-/64-
bit type and the other to memsize-type.
An example:
int *array;
size_t *sizetPtr = (size_t *)(array);
.otherwise
,
if
),(
64322
*
11
*
2
64322
*
21
*
1
215
false
TTtpTtp
TTtpTtptrue
ppF
Conversion of memsize-types to double
You should consider unsafe explicit and implicit conversions of a memsize-type to double and vice versa.
An example:
size_t a;
double b = a;
.otherwise
,if
),( 1221
216
false
TtDtTtDttrue
ttF
15. 15
Memsize-types in a function with the variable number of arguments
You should consider unsafe transfer of a memsize-type (except for pointers) to a function with the variable number of
arguments.
An example:
size_t a;
printf("%u", a);
Let K be a tuple of all the actual types serving as parameters of a function with the variable number of arguments.
Let the function be called a function with m arguments.
.otherwise
,..1,/if
)(7
false
miPTktrue
KF i
16. 16
Dangerous constants
You should consider unsafe constants of a particular type. Let’s introduce N set of integer numbers which can be
written by means of C++ language. Let’s introduce a set of "dangerous" constants NC . Example of "dangerous"
constants: 4, 32, 0xffffffff etc.
.otherwise
,if
)(8
false
Cctrue
cF
17. 17
Memsize-types in unions
You should consider unsafe presence of members of memsize-types in unions.
An example:
union PtrNumUnion {
char *m_p;
unsigned m_n;
} u;
Let’s call all the data types included into the union U tuple.
.otherwise
,if
)(9
false
TUtrue
UF
18. 18
Exceptions and memsize-types
You should consider unsafe throwing and processing of exceptions using memsize-types.
An example:
char *p1, *p2;
try {
throw (p1 – p2);
}
catch (int) {
...
}
.otherwise
,if
)(10
false
Tttrue
tF
19. 19
Conclusion
The rules of diagnosing potentially unsafe constructions from the viewpoint of 64-bit applications considered in the
article may be implemented in any static code analyzer.
But at present they are implemented in a complete form only in Viva64 code analyzer (www.viva64.com). Viva64
program product provides diagnoses of errors specific for 64-bit Windows applications. Viva64 is a lint-like static
analyzer of C/C++ code. Viva64 tool integrates into Visual Studio 2005/2008 development environment and provides
a convenient user interface for checking program projects.
20. 20
References
1. Scott Meyers, Martin Klaus "A First Look at C++ Program Analyzers.", 1997,
http://www.viva64.com/go.php?url=13.
2. Andrey Karpov, Evgeniy Ryzhkov. 20 issues of porting C++ code on the 64-bit platform. RSDN Magazine #1-
2007. pp. 65 – 75.
3. Alexey Kolosov, Evgeniy Ryzhkov, Andrey Karpov. 32 OpenMP traps for C++ developers. RSDN Magazine #2-
2008. pp. 3 – 17.
4. E. A. Ryzhkov, A.N. Karpov. Approaches to verification and testing of 64-bit applications. "Information
Technologies" №7, 2008, pp. 41 – 45.
5. S. McConnell. Perfect code. Master-class / translated from English – Moscow: "Russian Edition" publishing
house, St. Petersburg, 2007 – 896 pp.: illustrations.
6. System software / A.V. Gordeev, A.U. Molchanov. – St. Petersburg: Piter, 2002. – 736 pp.: illustrations.
7. Evgeniy Ryzhkov, Andrey Karpov. The essence of the VivaCore code analysis library. RSDN Magazine #1-2008.
pp. 56 – 63.