Skip to content

Instantly share code, notes, and snippets.

@yusukemihara
Last active April 17, 2020 04:39
Show Gist options
  • Select an option

  • Save yusukemihara/33f2eb90845dd1b7d6bf2dc8bb0c4d94 to your computer and use it in GitHub Desktop.

Select an option

Save yusukemihara/33f2eb90845dd1b7d6bf2dc8bb0c4d94 to your computer and use it in GitHub Desktop.
ツールによるCOBOLのInitialize漏れチェック
# 概要
簡単なCOBOLプログラムを作成してscan-build、およびvalgrindでInitialize漏れがチェックできるか確認した。
結論としては両ツールではチェックできなかった。
# TEST1.CBLのビルドおよびscan-build実行
`% ./build.sh`
結果をbuild.sh.outに記載
# valgrindの実行
`% valgrind ./TEST1`
valgrind.outに記載
#!/bin/bash -x
export COB_CC="scan-build-3.9 clang-3.9"
cobc -x -dynamic -debug -v -fixed -fimplicit-init -std=cobol85 -Wall TEST1.CBL
+ export 'COB_CC=scan-build-3.9 clang-3.9'
+ COB_CC='scan-build-3.9 clang-3.9'
+ cobc -x -dynamic -debug -v -fixed -fimplicit-init -std=cobol85 -Wall TEST1.CBL
preprocessing TEST1.CBL into /tmp/cob2290_0.cob
translating /tmp/cob2290_0.cob into /tmp/cob2290_0.c
scan-build-3.9 clang-3.9 -pipe -c -Wno-unused -fsigned-char -Wno-pointer-sign -o /tmp/cob2290_0.o /tmp/cob2290_0.c
scan-build: Using '/usr/lib/llvm-3.9/bin/clang' for static analysis
scan-build: Removing directory '/tmp/scan-build-2020-04-17-114539-2292-1' because it contains no reports.
scan-build: No bugs found.
scan-build-3.9 clang-3.9 -pipe -Wl,--export-dynamic -o TEST1 /tmp/cob2290_0.o -L/usr/lib -lcob -lm -lgmp -lncurses -ldb -ldl
scan-build: Using '/usr/lib/llvm-3.9/bin/clang' for static analysis
scan-build: Removing directory '/tmp/scan-build-2020-04-17-114539-2299-1' because it contains no reports.
scan-build: No bugs found.
/* Generated by cobc 1.1.0 */
/* Generated from TEST1.CBL */
/* Generated at 4月 17 2020 10:55:24 JST */
/* OpenCOBOL build date Nov 01 2019 08:21:30 */
/* OpenCOBOL package date Feb 06 2009 10:30:55 CET */
/* Compile command cobc -m -dynamic -debug -v -C -fixed -fimplicit-init -std=cobol85 -Wall -MT TEST1.so TEST1.CBL */
#define __USE_STRING_INLINES 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <libcob.h>
#define COB_SOURCE_FILE "TEST1.CBL"
#define COB_PACKAGE_VERSION "1.1"
#define COB_PATCH_LEVEL 0
/* Global variables */
#include "TEST1.c.h"
/* Function prototypes */
int TEST1 (void);
static int TEST1_ (const int);
/* Functions */
int
TEST1 ()
{
return TEST1_ (0);
}
static int
TEST1_ (const int entry)
{
/* Local variables */
#include "TEST1.c.l.h"
static int initialized = 0;
static cob_field *cob_user_parameters[COB_MAX_FIELD_PARAMS];
static struct cob_module module = { NULL, NULL, NULL, NULL, cob_user_parameters, 0, '.', '$', ',', 1, 1, 1, 0 };
/* Start of function code */
/* CANCEL callback handling */
if (unlikely(entry < 0)) {
if (!initialized) {
return 0;
}
initialized = 0;
return 0;
}
/* Initialize frame stack */
frame_ptr = &frame_stack[0];
frame_ptr->perform_through = 0;
frame_overflow = &frame_stack[COB_STACK_SIZE - 1];
/* Push module stack */
module.next = cob_current_module;
cob_current_module = &module;
/* Initialize program */
if (unlikely(initialized == 0))
{
if (!cob_initialized) {
cob_init (0, NULL);
}
cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL);
cob_set_cancel ((const char *)"TEST1", (void *)TEST1, (void *)TEST1_);
(*(int *) (b_1)) = 0;
memset (b_5, 32, 30);
initialized = 1;
}
cob_save_call_params = cob_call_params;
/* Entry dispatch */
goto l_2;
/* PROCEDURE DIVISION */
/* Entry TEST1 */
l_2:;
/* 000-MAIN SECTION */
/* MAIN PARAGRAPH */
/* TEST1.CBL:13: DISPLAY */
cob_set_location ("TEST1", "TEST1.CBL", 13, "000-MAIN", "MAIN PARAGRAPH", "DISPLAY");
{
cob_display (0, 1, 1, &f_6);
}
/* TEST1.CBL:14: DISPLAY */
cob_set_location ("TEST1", "TEST1.CBL", 14, "000-MAIN", "MAIN PARAGRAPH", "DISPLAY");
{
cob_display (0, 1, 1, &f_7);
}
/* TEST1.CBL:15: MOVE */
cob_set_location ("TEST1", "TEST1.CBL", 15, "000-MAIN", "MAIN PARAGRAPH", "MOVE");
{
cob_move (&f_6, &f_7);
}
/* TEST1.CBL:16: EXIT */
cob_set_location ("TEST1", "TEST1.CBL", 16, "000-MAIN", "MAIN PARAGRAPH", "EXIT");
{
goto exit_program;
}
/* Program exit */
exit_program:
/* Pop module stack */
cob_current_module = cob_current_module->next;
/* Program return */
return (*(int *) (b_1));
}
/* End functions */
/* Generated by cobc 1.1.0 */
/* Generated from TEST1.CBL */
/* Generated at 4月 17 2020 10:55:24 JST */
/* OpenCOBOL build date Nov 01 2019 08:21:30 */
/* OpenCOBOL package date Feb 06 2009 10:30:55 CET */
/* Compile command cobc -m -dynamic -debug -v -C -fixed -fimplicit-init -std=cobol85 -Wall -MT TEST1.so TEST1.CBL */
/* Frame stack declaration */
struct cob_frame {
int perform_through;
void *return_address;
};
/* Union for CALL statement */
union cob_call_union {
void *(*funcptr)();
int (*funcint)();
void *func_void;
};
union cob_call_union cob_unifunc;
/* Storage */
/* PROGRAM-ID : TEST1 */
static unsigned char b_1[4] __attribute__((aligned)); /* RETURN-CODE */
static unsigned char b_5[30] __attribute__((aligned)); /* A1 */
/* End of storage */
/* Attributes */
static const cob_field_attr a_1 = {33, 0, 0, 0, NULL};
/* Fields */
/* PROGRAM-ID : TEST1 */
static cob_field f_6 = {10, b_5, &a_1}; /* S01 */
static cob_field f_7 = {20, b_5 + 10, &a_1}; /* S02 */
/* End of fields */
/* Generated by cobc 1.1.0 */
/* Generated from TEST1.CBL */
/* Generated at 4月 17 2020 10:55:24 JST */
/* OpenCOBOL build date Nov 01 2019 08:21:30 */
/* OpenCOBOL package date Feb 06 2009 10:30:55 CET */
/* Compile command cobc -m -dynamic -debug -v -C -fixed -fimplicit-init -std=cobol85 -Wall -MT TEST1.so TEST1.CBL */
/* Define perform frame stack */
struct cob_frame *frame_overflow;
struct cob_frame *frame_ptr;
struct cob_frame frame_stack[255];
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST1.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A1.
03 S01 PIC X(10).
03 S02 PIC X(20).
**************************************************************************
PROCEDURE DIVISION.
000-MAIN SECTION.
DISPLAY S01.
DISPLAY S02.
MOVE S01 TO S02.
EXIT PROGRAM.
==1953== Memcheck, a memory error detector
==1953== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1953== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==1953== Command: ./TEST1
==1953==
==1953==
==1953== HEAP SUMMARY:
==1953== in use at exit: 36,850 bytes in 159 blocks
==1953== total heap usage: 228 allocs, 69 frees, 54,836 bytes allocated
==1953==
==1953== LEAK SUMMARY:
==1953== definitely lost: 271 bytes in 1 blocks
==1953== indirectly lost: 0 bytes in 0 blocks
==1953== possibly lost: 0 bytes in 0 blocks
==1953== still reachable: 36,579 bytes in 158 blocks
==1953== suppressed: 0 bytes in 0 blocks
==1953== Rerun with --leak-check=full to see details of leaked memory
==1953==
==1953== For counts of detected and suppressed errors, rerun with: -v
==1953== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment