- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
#include <stdio.h>;
void check(int x, int y) {
if (2*x == y && y < 0 && 0 <= 2*x) {
puts("Impossible!");
}
}
int main() {
check(0x7F80007F, 0xFF0000FE);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
#include <stdio.h>;
void check(int x, int y) {
if (2*x == y && y < 0 && 0 <= 2*x) {
puts("Impossible!");
}
}
int main() {
check(0x7F80007F, 0xFF0000FE);
}
https://runtimeverification.com/blog/?p=257
When writing code for a specific compiler you can rely on the implementation-specified behavior, but signed overflow is still problematic. GCC promises that conversions between integer types will be reduced modulo the appropriate power of two when the value is not representable in the target type. This means that with GCC the conversion above will initialize var to -0x112234 on any architecture that GCC supports. However, only initialization and other conversions are safe. GCC still considers signed overflow in arithmetic as undefined behavior, and optimizes under the assumption that there will be no overflow. This can lead to apparently impossible results when signed values do overflow. Compiled with -O3, this program prints “Impossible!”.
By adding apparently-redundant casts to 2*x to give (int)(2*(unsigned int)x), the calculation becomes implementation-specified behavior from an out-of-range conversion instead of undefined behavior. While this code may not be portable between compilers, GCC now guarantees the “impossible” code will not be executed even with -O3.
0
int r_k ( char *text, char *point, int d, int q ){
int n = strlen( text);
int m = strlen(point );
int h = (int) pow(d , m - 1 ) % q ;
int i;
int p = 0;
int t = 0;
int j ;
for(i = 0 ;i < m ; i++ ){
p = ( (d*p) + point[i]) % q;
t = ( (d*t) + text[i]) % q;
}
for(i = 0; i <= (n - m) ; i++ ){
if(p == t ){
for(j = 0 ; j < m ; j++)
if( text[i + j] != point[j])
break;
if ( j == m )
return i;
}
t = ( ( (d * (t - text[i] * h) ) + (text[i + m])) % q ) + q ;
}
return 0;
}
Даже " Касперский" сказал что это говно и молча удалил.
−1
#include <stdio.h>
int main(int argc, char *argv[])
{
int num=0;
for(;num<99999999;++num)
{
if(num<10)
fprintf(stdout, "0000000%d\n", num);
else if(num<100)
fprintf(stdout,"000000%d\n", num);
else if(num<1000)
fprintf(stdout, "00000%d\n", num);
else if(num<10000)
fprintf(stdout, "0000%d\n", num);
else if(num<100000)
fprintf(stdout, "000%d\n", num);
else if(num<1000000)
fprintf(stdout, "00%d\n", num);
else if(num<10000000)
fprintf(stdout, "0%d\n", num);
}
}
Генератор всех возможных пинов wps:D
+2
for(i==1;i<=1000;i++)
https://youtu.be/Tzl0ELY_TiM?t=89
И эти люди хотят кого-то учить программированию?
+2
for(uint64_t i = 0ULL; i <= 999999999ULL; i+= 1)
{
long double a = 0.00005l * i; // это чтоб в плавучке не накапливались ошибки.
somefunction(a);
....
}
0
long func_strtol(char *p , char **cpyar , int type ){
long int result = 0, stp = 0, t = 0,step = 0, integer = 0, sign = 1;
if (*p == 45 ){
sign = -1;
step++;
}
else if(*p == 43){
step++;
}
if (!type ){
type = 10;
}
if( type >= 0 && type <= 10 ) {
while ( isdigit( p[step])) {
step++;
}
}
else if( type >= 11 && type <= 36 ) {
while( (p[step ] - 55 <= ( type - 1 ) && isalpha( p[step] ) ||
(p[step ] - 87 <= ( type - 1) && isalpha( p[step] ) ||
isdigit( p[step])
) ) ) {
step++;
}
}
stp = step - 1;
while( isalpha( p[stp] ) || isdigit( p[stp] )){
if( isalpha( p[stp] ) ){
integer += p[stp] >= 97 ? (p[stp] - 87) * pow(type,t) : (p[stp] - 55) * pow(type,t);
}
else if((p[stp] - 48 ) < type ){
integer += (p[stp] - 48) * pow( type, t );
}
stp--;
t++;
}
*cpyar = step == 1 && *p == '-' ? &p[step - 1]: &p[step];
result = (integer ) * sign;
return result ;
}
Пойду почитаю "День Опричника"
−19
ideone.com/4DdZvo
Спойлер: Оно компилится, но выводит компилятор какую то поебень
+1
#include "hex.h"
#include "aes.h"
#include <stdio.h>
#define KEY (0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c)
#define DATA (0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34)
unsigned char enc[] = { BPP_AES_ENCRYPT_ARRAY(KEY, DATA) };
int main() {
for (int i=0; i<sizeof(enc); ++i) {
printf("%02X ", enc[i]);
}
printf("\n");
return 0;
}
−17
#undef NULL
#define NULL ((void *) 0xDEADBEEF)
И все идиотские проверки типа:
if (ptr && ptr->field == value) { do_something(); }
идут лесом.
−33
#include <http://govnokod.ru/21585>
// assembly output for f1_signed and f2_signed on GCC 7,6,5 ... versions are same
signed char f1_signed(signed char a1, signed char a2, signed char a3)
{
return MAXS(a1,a2,a3,a1,a2,a3);
}
signed char f2_signed(signed char a1, signed char a2, signed char a3)
{
return MAXS(a1,a2,a3);
}
// assembly output for f1_unsigned and f2_unsigned on GCC 7,6,5 ... versions are differend
// GCC compiler can't do same simplification for unsigned function
// This function produces much more assembler code than second
unsigned char f1_unsigned(unsigned char a1, unsigned char a2, unsigned char a3)
{
return MAXS(a1,a2,a3,a1,a2,a3);
}
unsigned char f2_unsigned(unsigned char a1, unsigned char a2, unsigned char a3)
{
return MAXS(a1,a2,a3);
}
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80574
Очередной мой багрепорт в GCC. Компилятор GCC может заоптимизировать повторяющуйся в MAXS хрень для signed char, но не может для unsigned
А вот Clang не может заоптимизировать ни то, ни другое. https://godbolt.org/g/7Kt9X0